revision-id: adaafcf5184375369c0c4b3ccb1e82e846024ef8 (mariadb-10.3.7-137-gadaafcf5184) parent(s): 8716bb3b72b7f5fed69b6dde413c2138f6d175b2 author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-08-16 13:55:36 +0200 message: MDEV-16930: Crash when VALUES in derived table contains expressions Give names to the value constructor columns as in SELECT-list. --- mysql-test/main/table_value_constr.result | 22 ++++++++++++++++++++-- mysql-test/main/table_value_constr.test | 13 +++++++++++++ sql/sql_yacc.yy | 13 +++++++++---- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/mysql-test/main/table_value_constr.result b/mysql-test/main/table_value_constr.result index 9e0a0968932..5b7f167cbde 100644 --- a/mysql-test/main/table_value_constr.result +++ b/mysql-test/main/table_value_constr.result @@ -11,7 +11,7 @@ values (1,2), (3,4), (5.6,0); 3.0 4 5.6 0 values ("abc", "def"); -abc def +"abc" "def" abc def # UNION that uses VALUES structure(s) select 1,2 @@ -92,7 +92,7 @@ we q values ("ab", "cdf") union select "ab","cdf"; -ab cdf +"ab" "cdf" ab cdf values (1,2) union @@ -2097,3 +2097,21 @@ v # with t as (values (),()) select 1 from t; ERROR HY000: Row with no elements is not allowed in table value constructor in this context +# +# MDEV-16930: expression in the first row of TVC specifying derived table +# +VALUES(1+1,2); +1+1 2 +2 2 +SELECT * FROM (VALUES(1+1,2)) t; +1+1 2 +2 2 +PREPARE stmt FROM "SELECT * FROM (VALUES(1+1,2)) t"; +EXECUTE stmt; +1+1 2 +2 2 +EXECUTE stmt; +1+1 2 +2 2 +DEALLOCATE PREPARE stmt; +# End of 10.3 tests diff --git a/mysql-test/main/table_value_constr.test b/mysql-test/main/table_value_constr.test index eb5ea59f829..9908f8e61f1 100644 --- a/mysql-test/main/table_value_constr.test +++ b/mysql-test/main/table_value_constr.test @@ -1075,3 +1075,16 @@ DELIMITER ;| --error ER_EMPTY_ROW_IN_TVC with t as (values (),()) select 1 from t; + +--echo # +--echo # MDEV-16930: expression in the first row of TVC specifying derived table +--echo # + +VALUES(1+1,2); +SELECT * FROM (VALUES(1+1,2)) t; +PREPARE stmt FROM "SELECT * FROM (VALUES(1+1,2)) t"; +EXECUTE stmt; +EXECUTE stmt; +DEALLOCATE PREPARE stmt; + +--echo # End of 10.3 tests diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index f915895a260..20cea4959eb 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -13306,15 +13306,20 @@ opt_values: ; values: - values ',' expr_or_default + values ',' remember_name expr_or_default remember_end { - if (unlikely(Lex->insert_list->push_back($3, thd->mem_root))) + if (unlikely(Lex->insert_list->push_back($4, thd->mem_root))) MYSQL_YYABORT; + // give some name in case of using in table value constuctor (TVC) + $4->set_name(thd, $3, (uint) ($5 - $3), thd->charset()); + } - | expr_or_default + | remember_name expr_or_default remember_end { - if (unlikely(Lex->insert_list->push_back($1, thd->mem_root))) + if (unlikely(Lex->insert_list->push_back($2, thd->mem_root))) MYSQL_YYABORT; + // give some name in case of using in table value constuctor (TVC) + $2->set_name(thd, $1, (uint) ($3 - $1), thd->charset()); } ;