summaryrefslogtreecommitdiff
path: root/sql/sql_update.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2023-01-09 22:39:39 -0800
committerIgor Babaev <igor@askmonty.org>2023-03-15 17:35:22 -0700
commit554278e24dbc2c0af9fcfd66c54ca6a99a3cf17f (patch)
tree49602d8ed671acc44e35835f02ec283e2df1e3ac /sql/sql_update.cc
parente2e3524d7222b713a0c0347fa6a2781e289c3b29 (diff)
downloadmariadb-git-554278e24dbc2c0af9fcfd66c54ca6a99a3cf17f.tar.gz
MDEV-7487 Semi-join optimization for single-table update/delete statements
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_update.cc')
-rw-r--r--sql/sql_update.cc12
1 files changed, 9 insertions, 3 deletions
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 4f0659d987a..ff1d70e7f8e 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -382,7 +382,6 @@ bool Sql_cmd_update::update_single_table(THD *thd)
DBUG_ENTER("Sql_cmd_update::update_single_table");
THD_STAGE_INFO(thd, stage_init_update);
- create_explain_query(thd->lex, thd->mem_root);
thd->table_map_for_update= 0;
@@ -2479,6 +2478,8 @@ int multi_update::do_updates()
table = cur_table->table;
if (table == table_to_update)
continue; // Already updated
+ if (table->file->pushed_rowid_filter)
+ table->file->disable_pushed_rowid_filter();
org_updated= updated;
tmp_table= tmp_tables[cur_table->shared];
tmp_table->file->extra(HA_EXTRA_CACHE); // Change to read cache
@@ -2673,7 +2674,8 @@ int multi_update::do_updates()
check_opt_it.rewind();
while (TABLE *tbl= check_opt_it++)
tbl->file->ha_rnd_end();
-
+ if (table->file->save_pushed_rowid_filter)
+ table->file->enable_pushed_rowid_filter();
}
DBUG_RETURN(0);
@@ -2684,6 +2686,8 @@ err:
}
err2:
+ if (table->file->save_pushed_rowid_filter)
+ table->file->enable_pushed_rowid_filter();
if (table->file->inited)
(void) table->file->ha_rnd_end();
if (tmp_table->file->inited)
@@ -2987,7 +2991,9 @@ bool Sql_cmd_update::prepare_inner(THD *thd)
{
goto err;
}
-
+ if (!multitable &&
+ select_lex->sj_subselects.elements)
+ multitable= true;
}
if (table_list->has_period())