Commit 4bdf9318 authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-13355: Assertion `using_unique_constraint || group_buff <= param->group_buff...

The code in OIN::optimize_inner() has this call

   calc_group_buffer(this, group_list)

the call is however bypassed when the optimizer figures out that the JOIN
has "Impossible WHERE".

If we attempt to calculate the value of a window function afterwards,
we will get a crash when trying to create a temporary table.

So, put a call to calc_group_buffer() here as well. It's a bit surprising
that all these steps are done for a query that will produce zero rows
but we are just following the approach taken by the fix for mdev-11999
here.
parent 2a1035b0
......@@ -3173,3 +3173,19 @@ Nth_value(i,1) OVER()
1
1
DROP TABLE t1;
#
# MDEV-13355: Assertion `using_unique_constraint || group_buff <= param->group_buff +
# param->group_length' failed in create_tmp_table
#
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1),(2);
SELECT * FROM (
SELECT
ROW_NUMBER() OVER(), i
FROM t1
WHERE 1=0
GROUP BY i
) AS sq
;
ROW_NUMBER() OVER() i
DROP TABLE t1;
......@@ -1953,4 +1953,19 @@ UNION ALL
( SELECT Nth_value(i,2) OVER() FROM t1 LIMIT 0 )
;
DROP TABLE t1;
--echo #
--echo # MDEV-13355: Assertion `using_unique_constraint || group_buff <= param->group_buff +
--echo # param->group_length' failed in create_tmp_table
--echo #
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1),(2);
SELECT * FROM (
SELECT
ROW_NUMBER() OVER(), i
FROM t1
WHERE 1=0
GROUP BY i
) AS sq
;
DROP TABLE t1;
......@@ -2176,6 +2176,7 @@ JOIN::optimize_inner()
choose_tableless_subquery_plan();
if (select_lex->have_window_funcs())
{
calc_group_buffer(this, group_list);
if (!(join_tab= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB))))
DBUG_RETURN(1);
need_tmp= 1;
......
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