summaryrefslogtreecommitdiff
path: root/sql/sql_delete.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2022-06-19 23:43:17 -0700
committerIgor Babaev <igor@askmonty.org>2022-06-20 16:43:44 -0700
commit2adebf4876283859066c11f23e89965733594363 (patch)
treec7bb7ab6f94b4d34c9adab2bab466f37b3ed7f56 /sql/sql_delete.cc
parentf7d2374083184261897e86bced158d9ae2c4aaaf (diff)
downloadmariadb-git-bb-10.10-mdev-7487.tar.gz
MDEV-7487 Semi-join optimization for single-table update/delete statementsbb-10.10-mdev-7487
This patch allows to use semi-join optimization at the top level of single-table update and delete statements. The problem of supporting such optimization became easy to resolve after processing a single-table update/delete statement started using JOIN structure. This allowed to use JOIN::prepare() not only for multi-table updates/deletes but for single-table ones as well. This was done in the patch for mdev-28883: Re-design the upper level of handling UPDATE and DELETE statements. Note that JOIN::prepare() detects all subqueries that can be considered as candidates for semi-join optimization. The code added by this patch looks for such candidates at the top level and if such candidates are found in the processed single-table update/delete the statement is handled in the same way as a multi-table update/delete. Approved by Oleksandr Byelkin <sanja@mariadb.com>
Diffstat (limited to 'sql/sql_delete.cc')
-rw-r--r--sql/sql_delete.cc11
1 files changed, 9 insertions, 2 deletions
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 2ff43316954..ed4b6beab34 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -1591,10 +1591,16 @@ bool Sql_cmd_delete::prepare_inner(THD *thd)
select_lex->order_list.first,
false, NULL, NULL, NULL,
select_lex, &lex->unit)))
-
{
goto err;
}
+
+ if (!multitable &&
+ select_lex->sj_subselects.elements)
+ multitable= true;
+
+ if (!multitable)
+ ((multi_delete *)result)->set_delete_tables(0);
}
if (multitable)
@@ -1638,7 +1644,8 @@ bool Sql_cmd_delete::prepare_inner(THD *thd)
{
TABLE_LIST *duplicate;
if ((duplicate= unique_table(thd, target_tbl->correspondent_table,
- lex->query_tables, 0)))
+ lex->query_tables, 0)) &&
+ !duplicate->select_lex->is_sj_subselect_lifted_to_top())
{
update_non_unique_table_error(target_tbl->correspondent_table,
"DELETE", duplicate);