[thelist] SQL Indexes

Rob Keniger rob at bigbang.net.au
Fri Oct 13 04:05:34 CDT 2000


on 2000-10-13 4:53 PM, Steve Cook at sck at biljettpoolen.se wrote:

> So what would be useful would be some general discussion of what indexes are
> and how one uses them in general - then I can go to the MySQL documentation
> and look up specific implementation.

Indexes are pre-sorted look-up tables of specific columns in your database
that are used to speed record search times.

Say you have a table called "users" and a column in that table called
"name". When data is entered, it is not sorted, so you end up with a list
like:

Marmaduke
Bob
David

When you then do a SELECT name FROM users WHERE name='David' on the column,
the database has to search through all the records to find all the records
which equal David. If, however, you had an index on the column, the database
stores a pre-sorted list of names:

Bob
David
Marmaduke

So to find all the Davids in the column the database just goes straight to
the "D"s and finds all the Davids next to each other - much faster than
having to check each record.

This is a vastly simplified explanation of how it works, of course.

-- 
 
Rob Keniger

big bang solutions

<mailto:rob at bigbang.net.au>
<http://www.bigbang.net.au>






More information about the thelist mailing list