I have a problem where I need to store Amazon.com’s order numbers into a MySQL table. Amazon.com order numbers are composed of numbers and hyphens, like 102-1234567-1234567 (17 numbers and 2 hyphens). I’ve seen this “number” stored as a string because of the hyphen in some instances, and, subsequently, a search on this column is a string search instead of a numerical search.
Right now, I’m just storing them as VARCHAR(19), but is there a way to store this so that it’s more efficient and faster in storing and retrieving? For example, I thought about parsing each numeric segments into one column of its own (3 columns total for one order “number”) and doing ... WHERE colA=102 AND colB=1234567 AND colC=1234567 to pull up a particular order, instead of doing ...WHERE col LIKE '102-1234567-1234567'. I know the former uses a lot less bytes, but is that also faster? The table I’m working on has over 100K rows and it grows by a tiny fraction every day.
Any suggestions or comments on how I should modify the structure or how I shouldn’t? TIA!
Don’t separate the three numeric looking pieces of Amazon’s current order number. Your database engine is fast enough to find an order by this number when its column is properly indexed. I get the ‘premature optimization’ sense from your question here.
Consider these suggestions:
widen your column to
varchar(100)or something larger than 19. You’re dependent on the vendor, and making a big assumption that their structure will never change.put an index on this column. 100K rows is a very small dataset.
find equality, rather than likeness as you’re currently doing.
WHERE Order='123-456-234