Commit 4a6b28c7 authored by Varun Gupta's avatar Varun Gupta

MDEV-22461: JOIN::make_aggr_tables_info(): Assertion `select_options & (1ULL << 17)' failed.

A temporary table is needed for window function computation but if only a NAMED WINDOW SPEC
is used and there is no window function, then there is no need to create a temporary
table as there is no stage to compute WINDOW FUNCTION
parent cf52dd17
......@@ -3724,5 +3724,24 @@ MAX(1) OVER () COUNT(a) abs(a)
1 0 NULL
drop table t1;
#
# MDEV-22461: JOIN::make_aggr_tables_info(): Assertion `select_options & (1ULL << 17)' failed.
#
CREATE TEMPORARY TABLE t0 (a INT PRIMARY KEY ) ;
INSERT INTO t0 VALUES (1),(2),(3);
SELECT a FROM t0
WHERE a < 8
GROUP BY 1.5
WINDOW v2 AS ( PARTITION BY a ORDER BY a DESC );
a
1
SELECT a, ROW_NUMBER() OVER v2
FROM t0
WHERE a < 8
GROUP BY 1.5
WINDOW v2 AS ( PARTITION BY a ORDER BY a DESC );
a ROW_NUMBER() OVER v2
1 1
drop table t0;
#
# End of 10.2 tests
#
......@@ -2426,6 +2426,26 @@ SELECT MAX(1) OVER (), COUNT(a), abs(a) FROM t1 WHERE FALSE;
drop table t1;
--echo #
--echo # MDEV-22461: JOIN::make_aggr_tables_info(): Assertion `select_options & (1ULL << 17)' failed.
--echo #
CREATE TEMPORARY TABLE t0 (a INT PRIMARY KEY ) ;
INSERT INTO t0 VALUES (1),(2),(3);
SELECT a FROM t0
WHERE a < 8
GROUP BY 1.5
WINDOW v2 AS ( PARTITION BY a ORDER BY a DESC );
SELECT a, ROW_NUMBER() OVER v2
FROM t0
WHERE a < 8
GROUP BY 1.5
WINDOW v2 AS ( PARTITION BY a ORDER BY a DESC );
drop table t0;
--echo #
--echo # End of 10.2 tests
--echo #
......@@ -2014,11 +2014,16 @@ JOIN::optimize_inner()
}
need_tmp= test_if_need_tmp_table();
//TODO this could probably go in test_if_need_tmp_table.
if (this->select_lex->window_specs.elements > 0) {
need_tmp= TRUE;
/*
If window functions are present then we can't have simple_order set to
TRUE as the window function needs a temp table for computation.
ORDER BY is computed after the window function computation is done, so
the sort will be done on the temp table.
*/
if (select_lex->have_window_funcs())
simple_order= FALSE;
}
/*
If the hint FORCE INDEX FOR ORDER BY/GROUP BY is used for the table
......
......@@ -1636,6 +1636,7 @@ class JOIN :public Sql_alloc
- 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.
- We are using WINDOW functions.
When the WITH ROLLUP modifier is present, we cannot skip temporary table
creation for the DISTINCT clause just because there are only const tables.
*/
......@@ -1645,7 +1646,8 @@ class JOIN :public Sql_alloc
((select_distinct || !simple_order || !simple_group) ||
(group_list && order) ||
MY_TEST(select_options & OPTION_BUFFER_RESULT))) ||
(rollup.state != ROLLUP::STATE_NONE && select_distinct));
(rollup.state != ROLLUP::STATE_NONE && select_distinct) ||
select_lex->have_window_funcs());
}
bool choose_subquery_plan(table_map join_tables);
void get_partial_cost_and_fanout(int end_tab_idx,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment