Skip to content

Commit 2f6a014

Browse files
committed
Merge 10.4 into 10.5
2 parents cf75793 + 7d5d9ea commit 2f6a014

File tree

6 files changed

+160
-4
lines changed

6 files changed

+160
-4
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;

mysql-test/main/partition_exchange.result

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,3 +1308,16 @@ ALTER TABLE t2 REMOVE PARTITIONING;
13081308
ALTER TABLE t1 EXCHANGE PARTITION pm WITH TABLE t2;
13091309
ERROR HY000: Non matching attribute 'TABLESPACE' between partition and table
13101310
DROP TABLE t1, t2;
1311+
#
1312+
# MDEV-14642 Assertion `table->s->db_create_options == part_table->s->db_create_options' failed in compare_table_with_partition
1313+
#
1314+
CREATE TABLE t1 (a INT) ROW_FORMAT=DYNAMIC PARTITION BY KEY(a) PARTITIONS 2;
1315+
CREATE TABLE t2 (a INT) ;
1316+
ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2;
1317+
ERROR HY000: Tables have different definitions
1318+
DROP TABLE t1, t2;
1319+
CREATE TABLE t1 (a INT, PRIMARY KEY(a)) ENGINE=InnoDB PARTITION BY KEY(a) PARTITIONS 2;
1320+
CREATE TABLE t2 (a INT, PRIMARY KEY(a)) CHECKSUM=1, ENGINE=InnoDB;
1321+
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
1322+
ERROR HY000: Tables have different definitions
1323+
DROP TABLE t1, t2;

mysql-test/main/partition_exchange.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,21 @@ ALTER TABLE t2 REMOVE PARTITIONING;
536536
ALTER TABLE t1 EXCHANGE PARTITION pm WITH TABLE t2;
537537
DROP TABLE t1, t2;
538538

539+
--echo #
540+
--echo # MDEV-14642 Assertion `table->s->db_create_options == part_table->s->db_create_options' failed in compare_table_with_partition
541+
--echo #
542+
CREATE TABLE t1 (a INT) ROW_FORMAT=DYNAMIC PARTITION BY KEY(a) PARTITIONS 2;
543+
CREATE TABLE t2 (a INT) ;
544+
--error ER_TABLES_DIFFERENT_METADATA
545+
ALTER TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2;
546+
547+
# Cleanup
548+
DROP TABLE t1, t2;
549+
550+
CREATE TABLE t1 (a INT, PRIMARY KEY(a)) ENGINE=InnoDB PARTITION BY KEY(a) PARTITIONS 2;
551+
CREATE TABLE t2 (a INT, PRIMARY KEY(a)) CHECKSUM=1, ENGINE=InnoDB;
552+
--error ER_TABLES_DIFFERENT_METADATA
553+
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
554+
555+
# Cleanup
556+
DROP TABLE t1, t2;

sql/sql_partition_admin.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,13 @@ static bool compare_table_with_partition(THD *thd, TABLE *table,
249249
my_error(ER_TABLES_DIFFERENT_METADATA, MYF(0));
250250
DBUG_RETURN(TRUE);
251251
}
252-
DBUG_ASSERT(table->s->db_create_options ==
253-
part_table->s->db_create_options);
252+
253+
if (table->s->db_create_options != part_table->s->db_create_options)
254+
{
255+
my_error(ER_TABLES_DIFFERENT_METADATA, MYF(0));
256+
DBUG_RETURN(TRUE);
257+
}
258+
254259
DBUG_ASSERT(table->s->db_options_in_use ==
255260
part_table->s->db_options_in_use);
256261

sql/sql_update.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,10 +2115,9 @@ int multi_update::prepare(List<Item> &not_used_values,
21152115
if (!tl)
21162116
DBUG_RETURN(1);
21172117
update.link_in_list(tl, &tl->next_local);
2118-
tl->shared= table_count++;
2118+
table_ref->shared= tl->shared= table_count++;
21192119
table->no_keyread=1;
21202120
table->covering_keys.clear_all();
2121-
table->pos_in_table_list= tl;
21222121
table->prepare_triggers_for_update_stmt_or_event();
21232122
table->reset_default_fields();
21242123
}

0 commit comments

Comments
 (0)