diff options
| author | Igor Babaev <igor@askmonty.org> | 2021-04-22 20:02:08 -0700 |
|---|---|---|
| committer | Igor Babaev <igor@askmonty.org> | 2021-04-22 20:02:08 -0700 |
| commit | e3a25793be936d9682a711a00d6b4bf708b6fb8d (patch) | |
| tree | 6f1047164d7df4499687d1e598d7b46128fcf200 /sql/sql_derived.cc | |
| parent | 6f271302b649ee11e7987b46fe24824c2ca2be7c (diff) | |
| download | mariadb-git-e3a25793be936d9682a711a00d6b4bf708b6fb8d.tar.gz | |
MDEV-24823 Crash with invalid multi-table update of view in 2nd execution of SP
Before this patch mergeable derived tables / view used in a multi-table
update / delete were merged before the preparation stage.
When the merge of a derived table / view is performed the on expression
attached to it is fixed and ANDed with the where condition of the select S
containing this derived table / view. It happens after the specification of
the derived table / view has been merged into S. If the ON expression refers
to a non existing field an error is reported and some other mergeable derived
tables / views remain unmerged. It's not a problem if the multi-table
update / delete statement is standalone. Yet if it is used in a stored
procedure the select with incompletely merged derived tables / views may
cause a problem for the second call of the procedure. This does not happen
for select queries using derived tables / views, because in this case their
specifications are merged after the preparation stage at which all ON
expressions are fixed.
This patch makes sure that merging of the derived tables / views used in a
multi-table update / delete statement is performed after the preparation
stage.
Approved by Oleksandr Byelkin <sanja@mariadb.com>
Diffstat (limited to 'sql/sql_derived.cc')
| -rw-r--r-- | sql/sql_derived.cc | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index 50b0178c6c9..eef2ae7d282 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -355,10 +355,6 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived) DBUG_RETURN(FALSE); } - if (thd->lex->sql_command == SQLCOM_UPDATE_MULTI || - thd->lex->sql_command == SQLCOM_DELETE_MULTI) - thd->save_prep_leaf_list= TRUE; - arena= thd->activate_stmt_arena_if_needed(&backup); // For easier test if (!derived->merged_for_insert || @@ -436,6 +432,7 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived) derived->on_expr= expr; derived->prep_on_expr= expr->copy_andor_structure(thd); } + thd->where= "on clause"; if (derived->on_expr && derived->on_expr->fix_fields_if_needed_for_bool(thd, &derived->on_expr)) { |
