summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorMartin Hansson <martin.hansson@sun.com>2010-09-13 13:33:19 +0200
committerMartin Hansson <martin.hansson@sun.com>2010-09-13 13:33:19 +0200
commit3beeb5d045241afb9d3733fba8dd4ec6e5b9dd86 (patch)
tree09ae4d00c4813027ff2ba4d09ac175a9fbf4df08 /sql/sql_select.cc
parentdaa6d1f4f322b1ceaa2fbbdeef76bbbd0b30dab1 (diff)
downloadmariadb-git-3beeb5d045241afb9d3733fba8dd4ec6e5b9dd86.tar.gz
Bug #50394: Regression in EXPLAIN with index scan, LIMIT, GROUP BY and
ORDER BY computed col GROUP BY implies ORDER BY in the MySQL dialect of SQL. Therefore, when an index on the first table in the query is used, and that index satisfies ordering according to the GROUP BY clause, the query optimizer estimates the number of tuples that need to be read from this index. If there is a LIMIT clause, table statistics on tables following this 'sort table' are employed. There may be a separate ORDER BY clause however, which mandates reading the whole 'sort table' anyway. But the previous estimate was left untouched. Fixed by removing the estimate from EXPLAIN output if GROUP BY is used in conjunction with an ORDER BY clause that mandates using a temporary table.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc9
1 files changed, 9 insertions, 0 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index f550f75c8b8..605819a1646 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -1487,6 +1487,15 @@ JOIN::optimize()
if (order)
{
/*
+ Do we need a temporary table due to the ORDER BY not being equal to
+ the GROUP BY? The call to test_if_skip_sort_order above tests for the
+ GROUP BY clause only and hence is not valid in this case. So the
+ estimated number of rows to be read from the first table is not valid.
+ We clear it here so that it doesn't show up in EXPLAIN.
+ */
+ if (need_tmp && (select_options & SELECT_DESCRIBE) != 0)
+ join_tab[const_tables].limit= 0;
+ /*
Force using of tmp table if sorting by a SP or UDF function due to
their expensive and probably non-deterministic nature.
*/