I have an indexed field users.username, which is only used in the admin interface. Because the table has currently lots of writes, I’d like to remove that index. Of course I want to keep the index searchable for admins.
I could extract the whole column, to move that index to another table. But it feels stupid because I’m already planning to move the write heavy fields into another table (with just one index).
Throwing in an search engine would be overkill.
Any ideas for a simple solution?
[edit]
I’ve just realized that the need for the admins to search and sort lots of fields has impact on many tables (which would actually need much more indexes). For the first step I’ll ensure that the admins get an dedicated server+db to keep off the slow sorts/searches from live servers and in the long run I’ll investigate if a search engine is suitable. Thanks all!
Maintaining an index only accessible by certain users is not supported in
MySQL, and even if it was, it would be as expensive as maintaining a usual index.Assuming the usernames are unique, you can create a separate index-like table like that:
, fill in on a timely basis:
and query it:
The first part does a normal search; the second part processes the usernames that were inserted in between the updates to
shadow_username; the third part is a fallback method which does a normal search only if previous two steps found nothing (that may happen if a user changed their username).If the username never changes, you should omit the third step.