Commit ad17875c authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-15563: Allow instant VARCHAR extension from <128 bytes

For up to 127 bytes length, InnoDB would use 1 byte for length, and
that byte would always be less than 128. If the maximum length is
longer than 255 bytes, InnoDB would use a variable-length encoding
for the length, using 1 byte for lengths up to 127 bytes, and
2 bytes for longer lengths.

Thus, 1-byte lengths are always compatible when the maximum size
changes from less than 128 bytes to anything longer.

Field_varstring::is_equal(): Return IS_EQUAL_PACK_LENGTH also when
converting from VARCHAR less than 128 bytes to any longer VARCHAR.
parent 8ef4105a
...@@ -412,6 +412,23 @@ ALTER TABLE t1 MODIFY f2 VARCHAR(300); ...@@ -412,6 +412,23 @@ ALTER TABLE t1 MODIFY f2 VARCHAR(300);
CALL get_table_id("test/t1", @tbl1_id); CALL get_table_id("test/t1", @tbl1_id);
SELECT @tbl1_id = @tbl_id; SELECT @tbl1_id = @tbl_id;
@tbl1_id = @tbl_id @tbl1_id = @tbl_id
1
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`f1` int(11) NOT NULL,
`f2` varchar(300) DEFAULT NULL,
KEY `idx` (`f2`(40))
) ENGINE=InnoDB DEFAULT CHARSET=latin1
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL,
f2 VARCHAR(128),
INDEX idx(f2(40)))ENGINE=InnoDB;
CALL get_table_id("test/t1", @tbl_id);
ALTER TABLE t1 MODIFY f2 VARCHAR(300);
CALL get_table_id("test/t1", @tbl1_id);
SELECT @tbl1_id = @tbl_id;
@tbl1_id = @tbl_id
0 0
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
......
...@@ -306,6 +306,18 @@ SELECT @tbl1_id = @tbl_id; ...@@ -306,6 +306,18 @@ SELECT @tbl1_id = @tbl_id;
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL,
f2 VARCHAR(128),
INDEX idx(f2(40)))ENGINE=InnoDB;
CALL get_table_id("test/t1", @tbl_id);
ALTER TABLE t1 MODIFY f2 VARCHAR(300);
CALL get_table_id("test/t1", @tbl1_id);
SELECT @tbl1_id = @tbl_id;
SHOW CREATE TABLE t1;
DROP TABLE t1;
CREATE TABLE t1(f1 INT NOT NULL, CREATE TABLE t1(f1 INT NOT NULL,
f2 VARCHAR(100), f2 VARCHAR(100),
INDEX idx(f2(40)))ENGINE=InnoDB; INDEX idx(f2(40)))ENGINE=InnoDB;
......
...@@ -7901,17 +7901,21 @@ Field *Field_varstring::new_key_field(MEM_ROOT *root, TABLE *new_table, ...@@ -7901,17 +7901,21 @@ Field *Field_varstring::new_key_field(MEM_ROOT *root, TABLE *new_table,
uint Field_varstring::is_equal(Create_field *new_field) uint Field_varstring::is_equal(Create_field *new_field)
{ {
if (new_field->length < field_length)
return IS_EQUAL_NO;
if (new_field->type_handler() == type_handler() && if (new_field->type_handler() == type_handler() &&
new_field->charset == field_charset && new_field->charset == field_charset &&
!new_field->compression_method() == !compression_method()) !new_field->compression_method() == !compression_method())
{ {
if (new_field->length == field_length) if (new_field->length == field_length)
return IS_EQUAL_YES; return IS_EQUAL_YES;
if (new_field->length > field_length && if (field_length <= 127 ||
((new_field->length <= 255 && field_length <= 255) || new_field->length <= 255 ||
(new_field->length > 255 && field_length > 255))) field_length > 255)
return IS_EQUAL_PACK_LENGTH; // VARCHAR, longer variable length return IS_EQUAL_PACK_LENGTH; // VARCHAR, longer length
} }
return IS_EQUAL_NO; return IS_EQUAL_NO;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment