diff options
author | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2017-06-27 12:26:38 +0300 |
---|---|---|
committer | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2017-06-28 15:23:36 +0300 |
commit | 23edc7c88f29d7bee01f39f1a58f4ada05f724c3 (patch) | |
tree | 4044cd44b1f6abe7c99f431b5417de95cee8249f | |
parent | 90038693903044bbbf7946ac128c3757ad33d7ba (diff) | |
download | mariadb-git-23edc7c88f29d7bee01f39f1a58f4ada05f724c3.tar.gz |
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.
-rw-r--r-- | mysql-test/r/win.result | 12 | ||||
-rw-r--r-- | mysql-test/t/win.test | 10 | ||||
-rw-r--r-- | sql/item.cc | 6 |
3 files changed, 25 insertions, 3 deletions
diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index ec83998aa98..a67c336e5b4 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -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; diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index 95d32c5bd14..0ecb2b35074 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -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; diff --git a/sql/item.cc b/sql/item.cc index 7ec50c2f472..30778132afc 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -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) |