MySQL Forums
Forum List  »  Performance

Re: MySQL not using indexes
Posted by: Rick James
Date: February 24, 2011 08:49PM

> Is a well-indexed query on a table of 72M rows expected to run at around 1 - 2 minutes?
It depends. Perhaps you now see that it might take less than a second, or could take many minutes. It depends on the combination of the index and the query.

Most indexes are structured in "BTrees". This provide very efficient lookup of a single row by the key being indexed. You can expect the query to take less than a second, regardless of table size.

BTrees also provide for very efficient "range" queries, like
SELECT * FROM tbl WHERE ts BETWEEN ... AND ...
This can fetch dozens to thousands of rows per second, regardless of table size.

Neither of those examples will register as "Using index". "Using index" really means "Using _only_ an index". But, if you have millions of rows, and your query has to scan the entire index (which also has millions of 'rows'), then this "index scan" could take a long time. Still, it is likely to be faster than scanning the entire dataset.

IN (...) does lots of single-row lookups.

name LIKE "Darr%" (find all names starting with Darr) is also a 'range' query. It starts at the first Darr, and scans sequentially until it has done all the `name` values starting with Darr.

When you don't have a useful index, it has to do a "table scan". This means reading every row.

name LIKE "%ell" has to do an index scan or table scan because the order of the index is useless without having a starting letter.

A table scan will be indicated by "ALL" in Explain's 'type'.
An index scan will say "index".
A range scan will say "range".

Note: If the optimizer decides that the 'range' is too big a percentage of the table, it will punt and turn it into a table scan.

Options: ReplyQuote


Subject
Views
Written By
Posted
3606
February 23, 2011 01:31AM
1210
February 23, 2011 08:16AM
1079
February 23, 2011 09:58AM
1178
February 24, 2011 09:26AM
1210
February 24, 2011 12:25PM
1455
February 24, 2011 03:36PM
1123
February 24, 2011 06:57PM
Re: MySQL not using indexes
1556
February 24, 2011 08:49PM
1043
February 25, 2011 12:52AM
1028
February 25, 2011 07:44AM
926
February 25, 2011 11:40AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.