Skip to content

Commit 852e138

Browse files
dr-mgrooverdan
authored andcommitted
MDEV-21245 InnoDB: Using a partial-field key prefix in search
ha_innobase::compare_key_parts(): If a full column index is being replaced with a column prefix index, return Compare_keys::NotEqual.
1 parent b471224 commit 852e138

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

mysql-test/suite/innodb/r/innodb_prefix_index_restart_server.result

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,19 @@ worklog5743;
9090
col_1_text = REPEAT("a", 3500) col_2_text = REPEAT("o", 3500)
9191
1 1
9292
DROP TABLE worklog5743;
93+
#
94+
# MDEV-21245 InnoDB: Using a partial-field key prefix in search
95+
#
96+
CREATE TABLE t1 (a VARCHAR(255), KEY k(a)) DEFAULT CHARSET=utf8mb3
97+
ENGINE=InnoDB;
98+
INSERT INTO t1 set a='';
99+
alter table t1 change a a varchar(3000);
100+
affected rows: 0
101+
info: Records: 0 Duplicates: 0 Warnings: 1
102+
Warnings:
103+
Note 1071 Specified key was too long; max key length is 3072 bytes
104+
SELECT * FROM t1 WHERE a IN ('');
105+
a
106+
107+
DROP TABLE t1;
108+
# End of 10.4 tests

mysql-test/suite/innodb/t/innodb_prefix_index_restart_server.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,17 @@ SELECT col_1_text = REPEAT("a", 3500) , col_2_text = REPEAT("o", 3500) FROM
9393
worklog5743;
9494

9595
DROP TABLE worklog5743;
96+
97+
--echo #
98+
--echo # MDEV-21245 InnoDB: Using a partial-field key prefix in search
99+
--echo #
100+
CREATE TABLE t1 (a VARCHAR(255), KEY k(a)) DEFAULT CHARSET=utf8mb3
101+
ENGINE=InnoDB;
102+
INSERT INTO t1 set a='';
103+
--enable_info
104+
alter table t1 change a a varchar(3000);
105+
--disable_info
106+
SELECT * FROM t1 WHERE a IN ('');
107+
DROP TABLE t1;
108+
109+
--echo # End of 10.4 tests

storage/innobase/handler/ha_innodb.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21199,6 +21199,10 @@ Compare_keys ha_innobase::compare_key_parts(
2119921199
if (old_part.length >= new_part.length)
2120021200
return Compare_keys::NotEqual;
2120121201

21202+
if (old_part.length == old_field.key_length() &&
21203+
new_part.length != new_field.key_length)
21204+
return Compare_keys::NotEqual;
21205+
2120221206
return Compare_keys::EqualButKeyPartLength;
2120321207
}
2120421208

0 commit comments

Comments
 (0)