Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7549839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:03:25+00:00 2026-05-30T10:03:25+00:00

Sorry, I’m just playing around with mysql and learning as I go along. Here’s

  • 0

Sorry, I’m just playing around with mysql and learning as I go along. Here’s my problem. I have a table(in python) with number values(for example {3:1,3:2,3:3}). I want to use the database as persistence storage of this variables(as they don’t fully fit in memory) but I want to try to make it as fast as possible.

Currently I am just using one column(indexed) in mysql and each entry in the dictionary gets its own row. I wanted to try to see if I could speed up reads/writes if I used two columns of INT as opposed to a CHAR column, but I need both columns to be unique to each other. In the example above all the data is unique and if I add another 3=1, then it’ll just overwrite the existing value, but 3=4 would create a new entry. How can I replicate that in mysql?

Also does my logic about the speed up make sense or will the select on two columns actually end up being more expensive than having one?

I’m building this from scratch so you don’t have to work within my existing solution, I’m very flexible to take any approach that works.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:03:26+00:00Added an answer on May 30, 2026 at 10:03 am

    Short version is that you can have multiple columns in a unique index

    // Create the test table
    CREATE TABLE testTable (
        col1 INT UNSIGNED NOT NULL,
        col2 INT UNSIGNED NOT NULL,
        col3 VARCHAR NOT NULL,
        PRIMARY KEY (col1,col2)
    );
    

    That will add a column with name uniqueOnCol1AndCol2 onto table testTable. You can then use your INSERT query as follows

    INSERT INTO testTable (
        col1,
        col2,
        col3
    ) VALUES (
        3,
        1,
        'Original value'
    ) ON DUPLICATE KEY UPDATE
    col1 = VALUES(col1)
    

    That would insert (3,1,’Original value’) into testTable. Following up with

    INSERT INTO testTable (
        col1,
        col2,
        col3
    ) VALUES (
        3,
        1,
        'New value'
    ) ON DUPLICATE KEY UPDATE
    col1 = VALUES(col1)
    

    would then overwrite col3 and make it ‘New value’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the basic question. I have looked at other answers here on Stackoverflow
Sorry about the cranky title, here's the example: <table> <tr> <th class=hey-1-aa></th> </tr> <tr>
Sorry this is basic, but I'm new to Python and Django. I have a
Sorry I am very new to open graph and have been having difficulty to
sorry I am a newbie I have been looking for an example on how
Sorry if it's a dull question, but why does execute function inserts a number
Sorry. I don't know a good title for this, but please look here: http://joshblog.net/projects/logic-gate-simulator/Logicly.html
Sorry if this is a noob question, but I have been given the dubious
Sorry for the general title. I am looking for a python re expression to
Sorry for not being specific, I just thought the context isn't important. Anyway the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.