diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 327b53ce6cd..0164aa4b610 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -2483,3 +2483,19 @@ Warnings: Note 1291 Column 'a' has duplicated value '' in ENUM drop table t1; set @@session.collation_server=default; +# +# MDEV-7765: Crash (Assertion `!table || (!table->write_set || +# bitmap_is_set(table->write_set, field_index) || +# bitmap_is_set(table->vcol_set, field_index))' fails) +# on using function over not created table +# +CREATE function f1() returns int +BEGIN +declare n int; +set n:= (select count(*) from t1); +return n; +end| +create table t1 as select f1(); +ERROR 42S02: Table 'test.t1' doesn't exist +drop function f1; +End of 5.5 tests diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index e066dc6277d..5c90c3e17a4 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -2061,3 +2061,24 @@ set @@session.collation_server=filename; create table t1(a enum('','')); drop table t1; set @@session.collation_server=default; + +--echo # +--echo # MDEV-7765: Crash (Assertion `!table || (!table->write_set || +--echo # bitmap_is_set(table->write_set, field_index) || +--echo # bitmap_is_set(table->vcol_set, field_index))' fails) +--echo # on using function over not created table +--echo # + +DELIMITER |; +CREATE function f1() returns int +BEGIN + declare n int; + set n:= (select count(*) from t1); + return n; +end| +DELIMITER ;| +-- error ER_NO_SUCH_TABLE +create table t1 as select f1(); +drop function f1; + +--echo End of 5.5 tests diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 52e059b5ef8..a089f5202aa 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -4151,6 +4151,8 @@ select_create::prepare(List &values, SELECT_LEX_UNIT *u) DBUG_RETURN(1); table->mark_columns_needed_for_insert(); table->file->extra(HA_EXTRA_WRITE_CACHE); + // Mark table as used + table->query_id= thd->query_id; DBUG_RETURN(0); }