Bug #31140 | SELECT BLOB in query ordered by datetime improves performance | ||
---|---|---|---|
Submitted: | 22 Sep 2007 4:36 | Modified: | 11 Dec 2007 6:22 |
Reporter: | Darren Gordon | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Optimizer | Severity: | S4 (Feature request) |
Version: | 5.0.45 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | BLOB, performance increase, selecting a blob, unrequired blob |
[22 Sep 2007 4:36]
Darren Gordon
[23 Sep 2007 6:13]
Valeriy Kravchuk
Thank you for a problem report. What exact version, 5.0.x, you had used? Is this problem repeatable with 5.0.45?
[24 Sep 2007 9:18]
Darren Gordon
It was discovered on 5.0.45 and has been repeated by others on various 5.0 versions, on various OS's. Updated version.
[25 Sep 2007 13:23]
MySQL Verification Team
Are you using query cache?. If yes please disable it and test again. Thanks in advance.
[25 Sep 2007 18:17]
Darren Gordon
Tested with non cached queries by setting query_cache_size to 0; and again with RESET QUERY CACHE. Issue occurs in both cases. Issue does not occur if the results are succesfully cached and reused. Thanks, Darren
[25 Sep 2007 18:29]
Darren Gordon
In case it's helpful, I was reading this on Sergey Petrunia's blog; perhaps the extra blob triggers 'Mode 2' of filesort(), which ends up being faster than 'Mode 1' ? --- http://s.petrunia.net/blog/?m=200708 filesort() has two modes of operation: 1. Mode 1: the sorted elements contain all required columns of the source table. The result of the sorting is a linear sequence of output tuples, there is no need to access the source table after the sort is done. 2. Mode 2: sort <sort_key, rowid> pairs and produce a sequence of rowids which one can use to get source table's rows in the required order (but this will be essentially hit the table in random order and is not very fast) Mode 1 is used whenever possible. Mode [2] is used when mode1 is not applicable. This is the case when the sorted tuples have blobs or variable-length columns (TODO: check w/ evgen). Unfortunately, the EXPLAIN output provides no clue about which mode is used, so you'll have to manually check for blobs in the output columns list.
[8 Dec 2007 20:06]
Valeriy Kravchuk
Thank you for a problem report and analysis. Yes, different filesort mode looks like a proper explanation. Do you agree to make this report a feature request for EXPLAIN to show filesort mode used?
[10 Dec 2007 10:57]
Darren Gordon
There is still the issue that method 2 is not selected for this particular query, despite being faster - unless mysql is tricked into doing so by adding a blob to the query. Perhaps this method is generally faster for dates and should be selected? I understand it may be difficult to select the fastest sort method for every single scenario; so I agree that showing the filesort method in EXPLAIN would be useful for optimizing such queries.
[11 Dec 2007 6:22]
Valeriy Kravchuk
I think, both considering all filesort implemetations for every query and mentioning selected one in EXPLAIN results are valid feature requests.