diff options
author | Sergei Petrunia <psergey@askmonty.org> | 2017-07-21 20:09:19 +0300 |
---|---|---|
committer | Sergei Petrunia <psergey@askmonty.org> | 2017-07-21 20:09:19 +0300 |
commit | 2a1035b004dfabcf3a7113be632b0030721a44d6 (patch) | |
tree | a33c169cf4fd0557fc8d3551c8fe8f0327aee3ee | |
parent | e2afdb1ee430cb9d030aeeedc85eb903cda5e5d1 (diff) | |
download | mariadb-git-bb-10.2-mdev13352.tar.gz |
MDEV-13351: Server crashes in st_select_lex::set_explain_type upon UNION with window functionbb-10.2-mdev13352
Make st_select_lex::set_explain_type() take into account that JOIN_TABs
it is traversing may be also post-join aggregation JOIN_TABs (which
have pos_in_table_list=NULL, etc).
-rw-r--r-- | mysql-test/r/win.result | 13 | ||||
-rw-r--r-- | mysql-test/t/win.test | 11 | ||||
-rw-r--r-- | sql/sql_lex.cc | 12 |
3 files changed, 33 insertions, 3 deletions
diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index 71521e747ab..c6707bd51bc 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3160,3 +3160,16 @@ SELECT ('bar',1) IN ( SELECT c, ROW_NUMBER() OVER (PARTITION BY c) FROM t1); ('bar',1) IN ( SELECT c, ROW_NUMBER() OVER (PARTITION BY c) FROM t1) 0 DROP TABLE t1; +# +# MDEV-13351: Server crashes in st_select_lex::set_explain_type upon UNION with window function +# +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1),(2); +SELECT Nth_value(i,1) OVER() FROM t1 +UNION ALL +( SELECT Nth_value(i,2) OVER() FROM t1 LIMIT 0 ) +; +Nth_value(i,1) OVER() +1 +1 +DROP TABLE t1; diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index be7049af8b4..77ca755378d 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -1943,3 +1943,14 @@ INSERT IGNORE INTO t1 VALUES ('foo'); SELECT ('bar',1) IN ( SELECT c, ROW_NUMBER() OVER (PARTITION BY c) FROM t1); DROP TABLE t1; +--echo # +--echo # MDEV-13351: Server crashes in st_select_lex::set_explain_type upon UNION with window function +--echo # +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1),(2); +SELECT Nth_value(i,1) OVER() FROM t1 +UNION ALL +( SELECT Nth_value(i,2) OVER() FROM t1 LIMIT 0 ) +; +DROP TABLE t1; + diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 21d7637ec06..f9330bc4375 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -4395,10 +4395,16 @@ void st_select_lex::set_explain_type(bool on_the_fly) if (join) { bool uses_cte= false; - for (JOIN_TAB *tab= first_explain_order_tab(join); tab; - tab= next_explain_order_tab(join, tab)) + for (JOIN_TAB *tab= first_linear_tab(join, WITHOUT_BUSH_ROOTS, + WITH_CONST_TABLES); + tab; + tab= next_linear_tab(join, tab, WITHOUT_BUSH_ROOTS)) { - if (tab->table && tab->table->pos_in_table_list->with) + /* + pos_in_table_list=NULL for e.g. post-join aggregation JOIN_TABs. + */ + if (tab->table && tab->table->pos_in_table_list && + tab->table->pos_in_table_list->with) { uses_cte= true; break; |