Skip to content

Commit 40d9dbb

Browse files
committed
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
1 parent 8881c01 commit 40d9dbb

File tree

3 files changed

+122
-2
lines changed

3 files changed

+122
-2
lines changed

mysql-test/main/multi_update.result

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,3 +1161,93 @@ ERROR 21000: Subquery returns more than 1 row
11611161
update t1 set a= (select 2 from t1 having (a = 3));
11621162
ERROR 21000: Subquery returns more than 1 row
11631163
drop tables t1;
1164+
#
1165+
# MDEV-28246 Optimizer uses all partitions during an update in MariaDB 10.6.x but not in 10.2.x
1166+
#
1167+
CREATE TABLE t1 (
1168+
part INT(1),
1169+
a INT(1),
1170+
b INT(1),
1171+
PRIMARY KEY (a,part),
1172+
INDEX b (b,part)
1173+
) PARTITION BY LIST (part) (
1174+
PARTITION Current VALUES IN (0),
1175+
PARTITION Relevant VALUES IN (1),
1176+
PARTITION Archive VALUES IN (2)
1177+
);
1178+
CREATE TABLE t2 LIKE t1;
1179+
INSERT INTO t1 (part,a,b) VALUES (0,0,0),(1,1,1),(2,2,2);
1180+
INSERT INTO t2 (part,a,b) VALUES (0,0,0),(1,1,1),(2,2,2);
1181+
# Expecting partition "Current"
1182+
EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=3 WHERE t2.part=0 AND t1.part=0;
1183+
EXPLAIN
1184+
{
1185+
"query_block": {
1186+
"select_id": 1,
1187+
"table": {
1188+
"table_name": "t2",
1189+
"partitions": ["Current"],
1190+
"access_type": "system",
1191+
"possible_keys": ["PRIMARY"],
1192+
"rows": 1,
1193+
"filtered": 100
1194+
},
1195+
"table": {
1196+
"table_name": "t1",
1197+
"partitions": ["Current"],
1198+
"access_type": "system",
1199+
"possible_keys": ["PRIMARY"],
1200+
"rows": 1,
1201+
"filtered": 100
1202+
}
1203+
}
1204+
}
1205+
# Expecting partition "Relevant"
1206+
EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=2 WHERE t2.part=1 AND t1.part=1;
1207+
EXPLAIN
1208+
{
1209+
"query_block": {
1210+
"select_id": 1,
1211+
"table": {
1212+
"table_name": "t2",
1213+
"partitions": ["Relevant"],
1214+
"access_type": "system",
1215+
"possible_keys": ["PRIMARY"],
1216+
"rows": 1,
1217+
"filtered": 100
1218+
},
1219+
"table": {
1220+
"table_name": "t1",
1221+
"partitions": ["Relevant"],
1222+
"access_type": "system",
1223+
"possible_keys": ["PRIMARY"],
1224+
"rows": 1,
1225+
"filtered": 100
1226+
}
1227+
}
1228+
}
1229+
# Expecting partition "Archive"
1230+
EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=3 WHERE t2.part=2 AND t1.part=2;
1231+
EXPLAIN
1232+
{
1233+
"query_block": {
1234+
"select_id": 1,
1235+
"table": {
1236+
"table_name": "t2",
1237+
"partitions": ["Archive"],
1238+
"access_type": "system",
1239+
"possible_keys": ["PRIMARY"],
1240+
"rows": 1,
1241+
"filtered": 100
1242+
},
1243+
"table": {
1244+
"table_name": "t1",
1245+
"partitions": ["Archive"],
1246+
"access_type": "system",
1247+
"possible_keys": ["PRIMARY"],
1248+
"rows": 1,
1249+
"filtered": 100
1250+
}
1251+
}
1252+
}
1253+
DROP TABLES t1, t2;

mysql-test/main/multi_update.test

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,3 +1098,34 @@ select a from t1 where a= (select 2 from t1 having (a = 3));
10981098
--error ER_SUBQUERY_NO_1_ROW
10991099
update t1 set a= (select 2 from t1 having (a = 3));
11001100
drop tables t1;
1101+
1102+
--echo #
1103+
--echo # MDEV-28246 Optimizer uses all partitions during an update in MariaDB 10.6.x but not in 10.2.x
1104+
--echo #
1105+
--source include/have_partition.inc
1106+
CREATE TABLE t1 (
1107+
part INT(1),
1108+
a INT(1),
1109+
b INT(1),
1110+
PRIMARY KEY (a,part),
1111+
INDEX b (b,part)
1112+
) PARTITION BY LIST (part) (
1113+
PARTITION Current VALUES IN (0),
1114+
PARTITION Relevant VALUES IN (1),
1115+
PARTITION Archive VALUES IN (2)
1116+
);
1117+
1118+
CREATE TABLE t2 LIKE t1;
1119+
INSERT INTO t1 (part,a,b) VALUES (0,0,0),(1,1,1),(2,2,2);
1120+
INSERT INTO t2 (part,a,b) VALUES (0,0,0),(1,1,1),(2,2,2);
1121+
1122+
--echo # Expecting partition "Current"
1123+
EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=3 WHERE t2.part=0 AND t1.part=0;
1124+
1125+
--echo # Expecting partition "Relevant"
1126+
EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=2 WHERE t2.part=1 AND t1.part=1;
1127+
1128+
--echo # Expecting partition "Archive"
1129+
EXPLAIN FORMAT=JSON UPDATE t2 JOIN t1 USING(a) SET t2.part=3 WHERE t2.part=2 AND t1.part=2;
1130+
1131+
DROP TABLES t1, t2;

sql/sql_update.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,10 +1977,9 @@ int multi_update::prepare(List<Item> &not_used_values,
19771977
if (!tl)
19781978
DBUG_RETURN(1);
19791979
update.link_in_list(tl, &tl->next_local);
1980-
tl->shared= table_count++;
1980+
table_ref->shared= tl->shared= table_count++;
19811981
table->no_keyread=1;
19821982
table->covering_keys.clear_all();
1983-
table->pos_in_table_list= tl;
19841983
table->prepare_triggers_for_update_stmt_or_event();
19851984
table->reset_default_fields();
19861985
}

0 commit comments

Comments
 (0)