Solution 2

If you need to retrieve a record quickly from a table with a large number of rows, then you are going to have to think about indexes. Basically, if you perform a search that uses a field that has an index on it, then the database engine could search through the index to perform the search, which should result in a quick retrieval.

Some points to note about indexes however.

First of all, they aren't a magic bullet. If you apply indexes to every field in a table just in case you search on that field, then you are going to make updating that table more time consuming because indexes do take a period of time to rebuild.

Secondly, it's pointless indexing a field that has a low distribution of data. What does this mean? Well, imagine that your database table contains a field holds one of two values, say Male or Female, then indexing this is absolutely pointless. (Note - this table would, of course, violate database normalisation and I wouldn't recommend this practice, but this should help you understand the issue).