| Bug #37359 | filesort can be more efficient | ||
|---|---|---|---|
| Submitted: | 12 Jun 2008 2:55 | Modified: | 12 Jun 2008 17:34 |
| Reporter: | Neel Nadgir | ||
| Status: | Verified | ||
| Category: | Server: Optimizer | Severity: | S4 (Feature request) |
| Version: | 6.0.5 | OS: | Any |
| Assigned to: | Target Version: | ||
| Tags: | innodb, filesort | ||
| Triage: | Triaged: D5 (Feature request) | ||
[12 Jun 2008 2:55]
Neel Nadgir
[12 Jun 2008 6:23]
Valeriy Kravchuk
Thank you for a reasonable feature request. I am not sure that dynamic allocation is a good solution for a general case. Maybe we should just add a session variable/optimizer hint to control maximum number of entires pre-allocated for cases like yours.
[12 Jun 2008 17:34]
Neel Nadgir
Allocation is not the problem; initializing it is the problem. The line that takes up the most time is <code>while (fields--) *(pos++) = (char_pos+= length); </code> in make_char_array() function. A link to a callstack profile is at http://blogs.sun.com/realneel/resource/filesort_trace.svg (Width of box is proportional to time consumed, and functions stack up as they are caled). The trace is with a debug build (compiler inlines make_char_array with optimization), so the numbers will be a higher.
[27 Jun 2008 10:22]
Igor Babaev
The function estimate_rows_upper_bound() should return a proper estimate in innodb.
[27 Jun 2008 10:23]
Igor Babaev
The function estimate_rows_upper_bound() should return a proper estimate in innodb.
[27 Jun 2008 10:39]
Sergei Golubchik
Igor, it does. It is defined to return the number of rows in the table. The better estimation is disabled in filesort - search for #ifdef CAN_TRUST_RANGE.
[24 Jul 2008 9:35]
James Day
One workaround for this is SHOW GLOBAL STATUS and look at Sort_merge_passes. If the value is zero or very few per minute, reduce the sort_buffer_size value until you start to see a few Sort_merge_passes each minute. The value that you are at will still probably be larger than ideal but it'll be closer than not checking. Sort merge passes are often not expensive, so don't be reluctant to experiment with lower values of sort_buffer_size. It's also quite common for production servers to benefit from larger values, so check that as well. Also note that you can set it larger or smaller for individual connections as required for the work that they are doing. This isn't specific to this bug report, it's general server tuning guidance. It doesn't eliminate the problem, just may reduce the size of the area being initialised and the speed penalty.
[16 Sep 2008 15:02]
Miguel Solorzano
Bug http://bugs.mysql.com/bug.php?id=39401 it was marked as duplicate of this one.
[7 Aug 14:24]
James Day
See this blog entry for more discussion: http://blogs.sun.com/realneel/entry/improving_filesort_performance_in_mysql
