Hello.

On Sat, Jun 23, 2001 at 01:01:41AM +0020, [EMAIL PROTECTED] wrote:
> I understand that indexes work so fast because they are usually smaller than the 
> original table, since they contain on average just 1 column, or at least less 
> information than the complete table. But how about a table with just 2 columns. 
> Would an index based on the same 2 columns speed up processing, more specific, 
> would it speed up a SELECT WHERE (the WHERE clause being related to the index 
> algoritm)

Yes.

The reason is, that in the table itself, the records are stored in no
particular order. So, to find a row, MySQL would have to scan the
whole table.

An index, with MyISAM tables, stored as a tree, implicitly has an
order of all values of the column(s) in question and has an additional
pointer to the data file, to indicate where the belonging record is
saved.

There are a number of methods for searching within sorted sets, but as
a simplification, have a look at binary search
(http://whatis.techtarget.com/definition/0,289893,sid9_gci349425,00.html).

It needs log_2(N) steps to find the locating an item, i.e. for
1,000,000,000 it needs only about 30 steps (power(2,30)=1073741824).
That means, only 30 disk reads instead of 1,000,000,000. And MySQL
even does better.

That's the main reason why an index works fast.

Bye,

        Benjamin.


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to