diff --git a/mysql-test/main/table_value_constr.result b/mysql-test/main/table_value_constr.result index 5a904cbca4b..9e0a0968932 100644 --- a/mysql-test/main/table_value_constr.result +++ b/mysql-test/main/table_value_constr.result @@ -2072,7 +2072,7 @@ select * from (values (1), (t1.b), (2)) as new_tvc; ERROR HY000: Field reference 't1.b' can't be used in table value constructor drop table t1; # -# MDEV-MDEV-15940: cursor over TVC +# MDEV-15940: cursor over TVC # BEGIN NOT ATOMIC DECLARE v INT; @@ -2092,3 +2092,8 @@ END; | v 1 +# +# MDEV-16038: empty row in TVC +# +with t as (values (),()) select 1 from t; +ERROR HY000: Row with no elements is not allowed in table value constructor in this context diff --git a/mysql-test/main/table_value_constr.test b/mysql-test/main/table_value_constr.test index 84f196b92a2..eb5ea59f829 100644 --- a/mysql-test/main/table_value_constr.test +++ b/mysql-test/main/table_value_constr.test @@ -1046,7 +1046,7 @@ select * from (values (1), (t1.b), (2)) as new_tvc; drop table t1; --echo # ---echo # MDEV-MDEV-15940: cursor over TVC +--echo # MDEV-15940: cursor over TVC --echo # DELIMITER |; @@ -1068,3 +1068,10 @@ END; | DELIMITER ;| + +--echo # +--echo # MDEV-16038: empty row in TVC +--echo # + +--error ER_EMPTY_ROW_IN_TVC +with t as (values (),()) select 1 from t; diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 20e42214e93..c55ac4f2001 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -7913,3 +7913,5 @@ ER_INDEX_FILE_FULL eng "The index file for table '%-.192s' is full" ER_UPDATED_COLUMN_ONLY_ONCE eng "The column %`s.%`s cannot be changed more than once in a single UPDATE statement" +ER_EMPTY_ROW_IN_TVC + eng "Row with no elements is not allowed in table value constructor in this context" diff --git a/sql/sql_tvc.cc b/sql/sql_tvc.cc index 7004c32e602..295aaded147 100644 --- a/sql/sql_tvc.cc +++ b/sql/sql_tvc.cc @@ -221,6 +221,12 @@ bool table_value_constr::prepare(THD *thd, SELECT_LEX *sl, uint cnt= first_elem->elements; Type_holder *holders; + if (cnt == 0) + { + my_error(ER_EMPTY_ROW_IN_TVC, MYF(0)); + DBUG_RETURN(true); + } + if (fix_fields_for_tvc(thd, li)) DBUG_RETURN(true);