diff --git a/mysql-test/r/sp_missing_4665.result b/mysql-test/r/sp_missing_4665.result new file mode 100644 index 00000000000..47587c180c6 --- /dev/null +++ b/mysql-test/r/sp_missing_4665.result @@ -0,0 +1,6 @@ +create table t (a int); +create or replace view v as select 1 from t where a; +delete from v where (select g()); +ERROR 42000: FUNCTION test.g does not exist +drop view v; +drop table t; diff --git a/mysql-test/t/sp_missing_4665.test b/mysql-test/t/sp_missing_4665.test new file mode 100644 index 00000000000..19e845e58c7 --- /dev/null +++ b/mysql-test/t/sp_missing_4665.test @@ -0,0 +1,9 @@ +# +# MDEV-4665 crash when referencing missing function in a subquery +# +create table t (a int); +create or replace view v as select 1 from t where a; +--error ER_SP_DOES_NOT_EXIST +delete from v where (select g()); +drop view v; +drop table t; diff --git a/sql/table.cc b/sql/table.cc index 32549568086..7c5f9ac82cb 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -3683,6 +3683,7 @@ bool TABLE_LIST::prep_where(THD *thd, Item **conds, bool no_where_clause) { DBUG_ENTER("TABLE_LIST::prep_where"); + bool res= FALSE; for (TABLE_LIST *tbl= merge_underlying_list; tbl; tbl= tbl->next_local) { @@ -3731,10 +3732,11 @@ bool TABLE_LIST::prep_where(THD *thd, Item **conds, if (tbl == 0) { if (*conds && !(*conds)->fixed) - (*conds)->fix_fields(thd, conds); - *conds= and_conds(*conds, where->copy_andor_structure(thd)); - if (*conds && !(*conds)->fixed) - (*conds)->fix_fields(thd, conds); + res= (*conds)->fix_fields(thd, conds); + if (!res) + *conds= and_conds(*conds, where->copy_andor_structure(thd)); + if (*conds && !(*conds)->fixed && !res) + res= (*conds)->fix_fields(thd, conds); } if (arena) thd->restore_active_arena(arena, &backup); @@ -3742,7 +3744,7 @@ bool TABLE_LIST::prep_where(THD *thd, Item **conds, } } - DBUG_RETURN(FALSE); + DBUG_RETURN(res); } /**