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!
Short version is that you can have multiple columns in a unique index
That will add a column with name
uniqueOnCol1AndCol2onto table testTable. You can then use your INSERT query as followsThat would insert (3,1,’Original value’) into testTable. Following up with
would then overwrite col3 and make it ‘New value’