I have a map from strings to integers. To store this map in a MySQL database I created the following table:
CREATE TABLE map(
Argument TEXT NOT NULL,
Image INTEGER NOT NULL
)
I chose the TEXT type for the argument because its length is unpredictable, currently the longest record has 2290 chars and the average length is 88 chars.
After I'd met the performance troubles I tried to add index on Argument
column, but found that I must to specify length, so to avoid this limitation I added a new integer column containing hash values (md5 or else) of Argument column values.
ALTER TABLE map ADD COLUMN ArgumentHash INTEGER;
And combined index
CREATE INDEX argument_index USING HASH ON map(ArgumentHash, Argument(80));
Since that time the problems with performance has disappeared. I'd like to ask whether it is a correct way to solve this problem.