MySQL Forums
Forum List  »  Performance

Re: Statistics
Posted by: Rick James
Date: April 27, 2010 08:08AM

Ask the prof:
mysql> show variables like '%prof%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| profiling              | OFF   |
| profiling_history_size | 15    |
+------------------------+-------+
Profiling is off for me.

So, if you are asking about "statistics" in PROCESSLIST, yeah, that has to do with figuring out the distribution of data for your table with respect to the query in question. When you say
WHERE x = 123
And x is at the beginning of a non-UNIQUE INDEX, the optimizer will find the first and last entry in the index for x=123, thereby discovering how many _index_ rows it will need to scan through -- IF it uses that index. If the answer is "big" (more than 10%-30% of the table size), it will (probably) decide to simply do a "table scan" instead. So, the time 'wasted' gathering that "statistic" was worth it, since the table scan is probably faster than bouncing between the index and the data. (That's just one example of statistics gathered on the way to deciding how to perform a query. See EXPLAIN.)

Oh, yes, if there are multiple indexes and multiple things ANDed together in the WHERE clause, it will perform similar statistics-gathering forays for other possible ways to perform the query. (No, MySQL does not do _all_ combinations possible; it uses an algorithm that is much faster, and _usually_ finds the 'best' anyway.)

Do not fear "statistics", it is your friend, and it helps you in the long run.

If you have slow queries (see the slowlog), let's discuss them. (And look around this forum -- there are lots of examples of how to speed up queries.)

Options: ReplyQuote


Subject
Views
Written By
Posted
4059
April 25, 2010 10:45AM
1387
April 26, 2010 09:14PM
1142
April 27, 2010 06:32AM
Re: Statistics
1467
April 27, 2010 08:08AM
1259
April 27, 2010 09:13AM
1235
April 27, 2010 08:00PM


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.