Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Split index with INT & VARCHAR into 2 fields?



9:01 pm on Jun 25, 2012 (gmt 0)

WebmasterWorld Administrator lifeinasia is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

I have a new table that will have a key of the form 12345-adbde, where the 12345 part will always be INT and the abcde part will be a VARCHAR.

Option 1 is to have MyKey field be a VARCHAR(30), with an index on MyKey. Option 2 is to have MyKey1 field be INT and MyKey2 field be a VARCHAR(20), with an index on both MyKey1 and MyKey2.

So searching with option 1 would be:
FROM MyTable
WHERE MyKey='12345-abcde'

Searching with option 2 would be:
FROM MyTable
WHERE MyKey1=12345' AND MyKey2='abcde'

I'd say 99% of the queries would be like this, although maybe 1% would just want the numeric part (easy enough to write for option 2, slightly more complicated for option 1, but still doable).

Would there be any performance advantage by using option 2? Note: there would only be about 2 dozen different values for the numeric part. For the 1% queries, I think there would be a definite performance boost with option 2.


10:10 pm on Jul 1, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

One other advantage top option 2 is that you would be using less space to store the numeric part which means you have a smaller database and it can hold more records in memory.
You may also want an index that is across MyKey1 and Mykey2.

Featured Threads

Hot Threads This Week

Hot Threads This Month