I have a table that has, among its primary keys, a VARCHAR(16) column that always contains 16 characters. I’m currently searching for various substrings at specific positions within this column using “LIKE CONCAT(‘_______________’, ?)”, “LIKE CONCAT(‘______________’, ? ‘_’)”, etc to use a 1 char example, but it is not necessarily always one char. The char varies with each parameter ? and through each query I do, and there are often many of these LIKEs ORed together. While automatically generating that query is no big deal, it still isn’t fast enough. I was considering splitting the column into 16 VARCHAR(1) columns and doing = ? queries, as they appear to go much faster for simple tests, but this is getting ridiculous.
Is there any way to make mysql index a certain string column by every character in it? Because that is basically what I need. Or is the best way to do it separating it all up into 1 char fields?
Some databases support functional indexes which would allow you to do this. Unfortunately MySQL isn’t one of them.
I’d go with this. You may also want to consider denormalizing and storing both representations if you also want to be able to perform a lookup on the entire key.