I am designing a table that will be used for cross-reference purposes with the structure:

id (BigInt) | cuid (Varchar(255)) | term (Varchar(255))

On a webpage a person will type in either a cuid or a term, and the program will look up the corresponding id to use internally in a program. There are a total of 2,669,793 entries that will be in the database (so id will span from 0 - 2669792).

I expect this might be rather slow. What techniques should I use to ensure the fastest possible lookup? The queries will resemble SELECT id WHERE cuid = ? or SELECT id WHERE term = ?.

Since I'm not looking up the id itself in the WHERE clause, I don't see how I would benefit from indexing (although id will inherently be indexed). I've heard of things such as breaking up a single table into multiple tables and doing some sort of merge operation. Any thoughts? Thanks.

有帮助吗?

解决方案

You can put indexes on any field, not just the id.

If your data is relatively static this would probably be beneficial. If you are going to query by multiple fields, then an index on multiple fields may also have benefits.

If your data is changing regularly, then additional indexes will have a processing cost, so its a balance that depends on your data usage

其他提示

You would need to provide indexes on both the cuid and term fields, assuming that id is primary key.

You would also need to make sure that you had enough memory allocated to keep those indexes in memory for best performance.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top