Commit 23edc7c8 authored by Vicențiu Ciorbaru's avatar Vicențiu Ciorbaru

MDEV-13186: main.win failure post MDEV-12336

During statement preparation st_order::item gets set to a value in
ref_ptr_array. During statement execution we were overriding that value,
causing subsequent checks for window functions to return true.

Whenever we do any setting from ref_ptr_array, make sure to always
store the value in all_fields as well.

For function items containing window functions, as MDEV-12336 has
discovered, we don't need to create a separate Item_direct_ref or
Item_aggregate_ref as they will be computed directly from the top-level
item once the window function argument columns are computed.
parent 90038693
......@@ -3085,3 +3085,15 @@ select max(id), rank() over (order by max(id)) from t1 where id < 3;
max(id) rank() over (order by max(id))
2 1
drop table t1;
#
# main.win failure post MDEV-12336
#
create table t(a decimal(35,10), b int);
insert into t values (1, 10), (2, 20), (3, 30);
prepare stmt from "SELECT (CASE WHEN sum(t.a) over (partition by t.b)=1 THEN 1000 ELSE 300 END) AS a FROM t";
execute stmt;
a
1000
300
300
drop table t;
......@@ -1877,3 +1877,13 @@ select count(max(id)) over (order by max(id)) from t1 where id < 3;
select max(id), rank() over (order by max(id)) from t1 where id < 3;
drop table t1;
--echo #
--echo # main.win failure post MDEV-12336
--echo #
create table t(a decimal(35,10), b int);
insert into t values (1, 10), (2, 20), (3, 30);
prepare stmt from "SELECT (CASE WHEN sum(t.a) over (partition by t.b)=1 THEN 1000 ELSE 300 END) AS a FROM t";
execute stmt;
drop table t;
......@@ -1920,6 +1920,9 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
point to the temporary table.
*/
split_sum_func(thd, ref_pointer_array, fields, split_flags);
if (type() == FUNC_ITEM) {
return;
}
}
else
{
......@@ -1979,9 +1982,6 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
&ref_pointer_array[el], 0, name))))
return; // fatal_error is set
}
else if (type() == FUNC_ITEM &&
((Item_func *) this)->with_window_func)
return;
else
{
if (!(item_ref= (new (thd->mem_root)
......
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