I’ve got the following situation: I want to store data, which represents, if a user is following another user. Another table, which I cannot touch, stores the users, where the username is the primary key (unfortunatly no id…).
The fact is, if one user follows another one, it doesn’t mean, that the other one is following the first one.
Right now, I designed the table with two varchar's (128) and a UNIQUE INDEX on these two varchar’s which represent the usernames.
The problem is, that I need to parse some old-styled system now, and I finished like 15% and I’ve got 550k entries on this table already.
The index is bigger then 16MB, and the data just 14MB.
What could I do, to save this data in a better way? As said, I cannot use id’s instead of the usernames, because the user-table uses the username as primary key.
As you have noticed, creating a seperate index on all columns essentially forces MySQL to duplicate all data in the index.
Instead of creating a seperate
unique index, you can create aprimary keyconsisting of both of your fields. MySQL uses theprimary keyas aclustered indexmaking sure your uniqueness constraint is still satisfied without increasing the size of your database.