Commit 164cf4f4 authored by Varun Gupta's avatar Varun Gupta

MDEV-16579: Wrong result of query using DISTINCT COUNT(*) OVER (*)

The query requires 2 temporary tables for execution, the window function
is always attached to the last temporary table, but in this case the
result field of the window function points to the first temporary table
rather than the last one.
Fixed this by not changing window function items with temporary table
items of the first temporary table.
parent 8129ff14
......@@ -3643,5 +3643,15 @@ x
foo
drop table t1;
#
# MDEV-16579: Wrong result of query using DISTINCT COUNT(*) OVER (*)
#
CREATE TABLE t1 (i int) ;
INSERT INTO t1 VALUES (1),(0),(1),(2),(0),(1),(2),(1),(2);
SELECT DISTINCT COUNT(*) OVER (), MOD(MIN(i),2) FROM t1 GROUP BY i ;
COUNT(*) OVER () MOD(MIN(i),2)
3 0
3 1
drop table t1;
#
# End of 10.2 tests
#
......@@ -2351,6 +2351,16 @@ INSERT INTO t1 VALUES (1),(2),(3);
SELECT (SELECT MIN('foo') OVER() FROM t1 LIMIT 1) as x;
drop table t1;
--echo #
--echo # MDEV-16579: Wrong result of query using DISTINCT COUNT(*) OVER (*)
--echo #
CREATE TABLE t1 (i int) ;
INSERT INTO t1 VALUES (1),(0),(1),(2),(0),(1),(2),(1),(2);
SELECT DISTINCT COUNT(*) OVER (), MOD(MIN(i),2) FROM t1 GROUP BY i ;
drop table t1;
--echo #
--echo # End of 10.2 tests
--echo #
......@@ -23624,7 +23624,8 @@ change_to_use_tmp_fields(THD *thd, Ref_ptr_array ref_pointer_array,
for (uint i= 0; (item= it++); i++)
{
Field *field;
if (item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM)
if ((item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM) ||
item->with_window_func)
item_field= item;
else if (item->type() == Item::FIELD_ITEM)
item_field= item->get_tmp_table_item(thd);
......
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