diff options
author | Oleg Smirnov <olernov@gmail.com> | 2022-05-13 18:10:11 +0400 |
---|---|---|
committer | Oleg Smirnov <olernov@gmail.com> | 2022-05-19 08:31:01 +0400 |
commit | 40d9dbb28f43708b498a4d62f61dc34fd87eb9b9 (patch) | |
tree | 678178dac0b50a5a7e4fc97b4b12080612632473 | |
parent | 8881c0100e2131077410b360b27b7af30db56e1a (diff) | |
download | mariadb-git-40d9dbb28f43708b498a4d62f61dc34fd87eb9b9.tar.gz |
MDEV-28246 Optimizer uses all partitions after upgrade to 10.3
Cause: a copy of the joined TABLE_LIST is created during multi_update::prepare
and TABLE::pos_in_table_list of the tables are set to point to the new
TABLE_LIST object. This prevents some optimization steps to perform correctly.
Solution: do not update pos_in_table_list during multi_update::prepare
-rw-r--r-- | mysql-test/main/multi_update.result | 90 | ||||
-rw-r--r-- | mysql-test/main/multi_update.test | 31 | ||||
-rw-r--r-- | sql/sql_update.cc | 3 |
3 files changed, 122 insertions, 2 deletions
diff --git a/mysql-test/main/multi_update.result b/mysql-test/main/multi_update.result index 71eafbf7e17..68d15d49b50 100644 --- a/mysql-test/main/multi_update.result +++ b/mysql-test/main/multi_update.result @@ -1161,3 +1161,93 @@ ERROR 21000: Subquery returns more than 1 row update t1 set a= (select 2 from t1 having (a = 3)); ERROR 21000: Subquery returns more than 1 row drop tables t1; +# +# MDEV-28246 Optimizer uses all partitions during an update in MariaDB 10.6.x but not in 10.2.x +# +CREATE TABLE t1 ( +part INT(1), +a INT(1), +b INT(1), +PRIMARY KEY (a,part), +INDEX b (b,part) +) PARTITION BY LIST (part) ( +PARTITION Current VALUES IN (0), +PARTITION Relevant VALUES IN (1), +PARTITION Archive VALUES IN (2) +); +CREATE TABLE t2 LIKE t1; +INSERT INTO t1 (part,a,b) VALUES (0,0,0),(1,1,1),(2,2,2); +INSERT INTO t2 (part,a,b) VALUES (0,0,0),(1,1,1),(2,2,2); +# Expecting partition "Current" +EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=3 WHERE t2.part=0 AND t1.part=0; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "t2", + "partitions": ["Current"], + "access_type": "system", + "possible_keys": ["PRIMARY"], + "rows": 1, + "filtered": 100 + }, + "table": { + "table_name": "t1", + "partitions": ["Current"], + "access_type": "system", + "possible_keys": ["PRIMARY"], + "rows": 1, + "filtered": 100 + } + } +} +# Expecting partition "Relevant" +EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=2 WHERE t2.part=1 AND t1.part=1; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "t2", + "partitions": ["Relevant"], + "access_type": "system", + "possible_keys": ["PRIMARY"], + "rows": 1, + "filtered": 100 + }, + "table": { + "table_name": "t1", + "partitions": ["Relevant"], + "access_type": "system", + "possible_keys": ["PRIMARY"], + "rows": 1, + "filtered": 100 + } + } +} +# Expecting partition "Archive" +EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=3 WHERE t2.part=2 AND t1.part=2; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "t2", + "partitions": ["Archive"], + "access_type": "system", + "possible_keys": ["PRIMARY"], + "rows": 1, + "filtered": 100 + }, + "table": { + "table_name": "t1", + "partitions": ["Archive"], + "access_type": "system", + "possible_keys": ["PRIMARY"], + "rows": 1, + "filtered": 100 + } + } +} +DROP TABLES t1, t2; diff --git a/mysql-test/main/multi_update.test b/mysql-test/main/multi_update.test index 3ee36f97fc5..5f4b5fc8ec3 100644 --- a/mysql-test/main/multi_update.test +++ b/mysql-test/main/multi_update.test @@ -1098,3 +1098,34 @@ select a from t1 where a= (select 2 from t1 having (a = 3)); --error ER_SUBQUERY_NO_1_ROW update t1 set a= (select 2 from t1 having (a = 3)); drop tables t1; + +--echo # +--echo # MDEV-28246 Optimizer uses all partitions during an update in MariaDB 10.6.x but not in 10.2.x +--echo # +--source include/have_partition.inc +CREATE TABLE t1 ( + part INT(1), + a INT(1), + b INT(1), + PRIMARY KEY (a,part), + INDEX b (b,part) +) PARTITION BY LIST (part) ( + PARTITION Current VALUES IN (0), + PARTITION Relevant VALUES IN (1), + PARTITION Archive VALUES IN (2) +); + +CREATE TABLE t2 LIKE t1; +INSERT INTO t1 (part,a,b) VALUES (0,0,0),(1,1,1),(2,2,2); +INSERT INTO t2 (part,a,b) VALUES (0,0,0),(1,1,1),(2,2,2); + +--echo # Expecting partition "Current" +EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=3 WHERE t2.part=0 AND t1.part=0; + +--echo # Expecting partition "Relevant" +EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=2 WHERE t2.part=1 AND t1.part=1; + +--echo # Expecting partition "Archive" +EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=3 WHERE t2.part=2 AND t1.part=2; + +DROP TABLES t1, t2; diff --git a/sql/sql_update.cc b/sql/sql_update.cc index a6a0b78259d..66c3acedb23 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1977,10 +1977,9 @@ int multi_update::prepare(List<Item> ¬_used_values, if (!tl) DBUG_RETURN(1); update.link_in_list(tl, &tl->next_local); - tl->shared= table_count++; + table_ref->shared= tl->shared= table_count++; table->no_keyread=1; table->covering_keys.clear_all(); - table->pos_in_table_list= tl; table->prepare_triggers_for_update_stmt_or_event(); table->reset_default_fields(); } |