summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorAlexey Kopytov <Alexey.Kopytov@Sun.com>2009-11-06 09:44:01 +0300
committerAlexey Kopytov <Alexey.Kopytov@Sun.com>2009-11-06 09:44:01 +0300
commit39f9a3ffd0de8828be2a43b9674a19fa58c52f98 (patch)
treedeebaa6d3b8c53f993b541d23de94fc1a893f385 /sql/sql_select.cc
parent43358bccd1227d8b7a28c64b1e2e262ab8f643d2 (diff)
downloadmariadb-git-39f9a3ffd0de8828be2a43b9674a19fa58c52f98.tar.gz
Bug #48475: DISTINCT is ignored with GROUP BY WITH ROLLUP and
only const tables The problem was caused by two shortcuts in the optimizer that are inapplicable in the ROLLUP case. Normally in a case when only const tables are involved in a query, DISTINCT clause can be safely optimized away since there may be only one row produced by the join. Similarly, we don't need to create a temporary table to resolve DISTINCT/GROUP BY/ORDER BY. Both of these are inapplicable when the WITH ROLLUP modifier is present. Fixed by disabling the said optimizations for the WITH ROLLUP case. mysql-test/r/olap.result: Added a test case for bug #48475. mysql-test/t/olap.test: Added a test case for bug #48475. sql/sql_select.cc: Disabled const-only table optimizations for the WITH ROLLUP case.
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc23
1 files changed, 16 insertions, 7 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 51794c1f158..1ee31c788ff 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -929,14 +929,20 @@ JOIN::optimize()
DBUG_RETURN(1);
}
- if (select_lex->olap == ROLLUP_TYPE && rollup_process_const_fields())
+ if (rollup.state != ROLLUP::STATE_NONE)
{
- DBUG_PRINT("error", ("Error: rollup_process_fields() failed"));
- DBUG_RETURN(1);
+ if (rollup_process_const_fields())
+ {
+ DBUG_PRINT("error", ("Error: rollup_process_fields() failed"));
+ DBUG_RETURN(1);
+ }
+ }
+ else
+ {
+ /* Remove distinct if only const tables */
+ select_distinct= select_distinct && (const_tables != tables);
}
- /* Remove distinct if only const tables */
- select_distinct= select_distinct && (const_tables != tables);
thd_proc_info(thd, "preparing");
if (result->initialize_tables(this))
{
@@ -1216,11 +1222,14 @@ JOIN::optimize()
- We are using an ORDER BY or GROUP BY on fields not in the first table
- We are using different ORDER BY and GROUP BY orders
- The user wants us to buffer the result.
+ When the WITH ROLLUP modifier is present, we cannot skip temporary table
+ creation for the DISTINCT clause just because there are only const tables.
*/
- need_tmp= (const_tables != tables &&
+ need_tmp= ((const_tables != tables &&
((select_distinct || !simple_order || !simple_group) ||
(group_list && order) ||
- test(select_options & OPTION_BUFFER_RESULT)));
+ test(select_options & OPTION_BUFFER_RESULT))) ||
+ rollup.state != ROLLUP::STATE_NONE && select_distinct);
// No cache for MATCH
make_join_readinfo(this,