From 4ff283dba679ba3a53306f236f1d682d00d638cf Mon Sep 17 00:00:00 2001 From: casazhang Date: Mon, 27 Sep 2021 14:28:06 +0800 Subject: [PATCH] Bug#105045 Switch slice before reaching execution end in WindowIterator::Read --- mysql-test/r/window_functions_bugs.result | 17 +++++++++++++++++ mysql-test/t/window_functions_bugs.test | 12 ++++++++++++ sql/window_iterators.cc | 5 +++-- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/window_functions_bugs.result b/mysql-test/r/window_functions_bugs.result index b9b9d85..c1ea23c 100644 --- a/mysql-test/r/window_functions_bugs.result +++ b/mysql-test/r/window_functions_bugs.result @@ -1092,3 +1092,20 @@ SELECT JSON_ARRAY(LEAD(CAST('true' AS JSON), 2, CAST('' AS JSON)) OVER (), ''); ERROR 22032: Invalid JSON text in argument 1 to function cast_as_json: "The document is empty." at position 0. SELECT JSON_ARRAY(JSON_ARRAYAGG(CAST('' AS JSON)) OVER (), ''); ERROR 22032: Invalid JSON text in argument 1 to function cast_as_json: "The document is empty." at position 0. +# +# Bug#105045: Switch slice before reaching execution end +# +create table t33(a int, b double); +insert into t33 values(1,2.1); +insert into t33 values(2,1.4); +insert into t33 values(1,2.56); +insert into t33 values(2,2.23); +select a, sum(b)+1 as cnt, row_number() over(order by sum(b) desc) as rn from t33 group by a order by rn; +a cnt rn +1 5.66 1 +2 4.63 2 +select a, round(sum(b), 1) as cnt, row_number() over(order by sum(b) desc) as rn from t33 group by a order by rn desc; +a cnt rn +2 3.6 2 +1 4.7 1 +drop table t33; diff --git a/mysql-test/t/window_functions_bugs.test b/mysql-test/t/window_functions_bugs.test index f5bf12f..01ca40b 100644 --- a/mysql-test/t/window_functions_bugs.test +++ b/mysql-test/t/window_functions_bugs.test @@ -619,3 +619,15 @@ SELECT JSON_ARRAY(NTH_VALUE(CAST('' AS JSON), 1) OVER (), ''); SELECT JSON_ARRAY(LEAD(CAST('true' AS JSON), 2, CAST('' AS JSON)) OVER (), ''); --error ER_INVALID_JSON_TEXT_IN_PARAM SELECT JSON_ARRAY(JSON_ARRAYAGG(CAST('' AS JSON)) OVER (), ''); + +--echo # +--echo # Bug#105045: Switch slice before reaching execution end +--echo # +create table t33(a int, b double); +insert into t33 values(1,2.1); +insert into t33 values(2,1.4); +insert into t33 values(1,2.56); +insert into t33 values(2,2.23); +select a, sum(b)+1 as cnt, row_number() over(order by sum(b) desc) as rn from t33 group by a order by rn; +select a, round(sum(b), 1) as cnt, row_number() over(order by sum(b) desc) as rn from t33 group by a order by rn desc; +drop table t33; diff --git a/sql/window_iterators.cc b/sql/window_iterators.cc index cb0f140..c8133a3 100644 --- a/sql/window_iterators.cc +++ b/sql/window_iterators.cc @@ -1563,12 +1563,13 @@ int WindowIterator::Read() { SwitchSlice(m_join, m_input_slice); int err = m_source->Read(); + + SwitchSlice(m_join, m_output_slice); + if (err != 0) { return err; } - SwitchSlice(m_join, m_output_slice); - if (copy_funcs(m_temp_table_param, thd(), CFT_HAS_NO_WF)) return 1; m_window->check_partition_boundary(); -- 1.8.3.1