Commit 177c191f authored by Monty's avatar Monty

MDEV-11606 Server crashes in mi_make_key / sort_key_read

Problem was that one internal record buffer in MYISAM was not big enough to handle virtual fields.
Fixed by extending buffer.

Fixed test case to 79 characters
parent c9b3e453
create table t1 (a int, b int as (a+1), c int, index(b));
insert t1 (a,c) values (0x7890abcd, 0x76543210);
insert t1 (a,c) select seq, sin(seq)*10000 from seq_1_to_1000;
explain select * from t1 where b=10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref b b 5 const 1
select * from t1 where b=10;
a b c
9 10 4121
MyISAM file: datadir/test/t1
Record format: Fixed length
Character set: latin1_swedish_ci (8)
Data records: 1001 Deleted blocks: 0
Recordlength: 9
table description:
Key Start Len Index Type
1 10 4 multip. long NULL
update t1 set a=20 where b=10;
select * from t1 where b=10;
a b c
select * from t1 where b=21;
a b c
20 21 4121
20 21 9129
delete from t1 where b=21;
select * from t1 where b=21;
a b c
alter table t1 add column d char(20) as (concat(a,c));
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
create index i on t1 (d);
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
check table t1 quick;
Table Op Msg_type Msg_text
test.t1 check status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
check table t1 medium;
Table Op Msg_type Msg_text
test.t1 check status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
check table t1 extended;
Table Op Msg_type Msg_text
test.t1 check status OK
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 b 1 b A 999 NULL NULL YES BTREE
t1 1 i 1 d A 999 NULL NULL YES BTREE
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
delete from t1 where b=12;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 b 1 b A 998 NULL NULL YES BTREE
t1 1 i 1 d A 998 NULL NULL YES BTREE
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
optimize table t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 b 1 b A 998 NULL NULL YES BTREE
t1 1 i 1 d A 998 NULL NULL YES BTREE
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
repair table t1;
Table Op Msg_type Msg_text
test.t1 repair status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
repair table t1 quick;
Table Op Msg_type Msg_text
test.t1 repair status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
repair table t1 extended;
Table Op Msg_type Msg_text
test.t1 repair status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
repair table t1 use_frm;
Table Op Msg_type Msg_text
test.t1 repair warning Number of rows changed from 0 to 998
test.t1 repair status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
update t1 set a=30 where b=11;
select * from t1 where b=11;
a b c d
select * from t1 where b=31;
a b c d
30 31 -5440 30-5440
30 31 -9880 30-9880
drop table t1;
SET @@session.storage_engine = 'MyISAM';
# - UNIQUE KEY
# - INDEX
......@@ -325,3 +209,157 @@ INDEX(vc(32))
);
DELETE FROM t1 WHERE vc IS NULL ORDER BY pk;
DROP TABLE t1;
#
# Original test
#
create table t1 (a int, b int as (a+1), c int, index(b));
insert t1 (a,c) values (0x7890abcd, 0x76543210);
insert t1 (a,c) select seq, sin(seq)*10000 from seq_1_to_1000;
explain select * from t1 where b=10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ref b b 5 const 1
select * from t1 where b=10;
a b c
9 10 4121
MyISAM file: datadir/test/t1
Record format: Fixed length
Character set: latin1_swedish_ci (8)
Data records: 1001 Deleted blocks: 0
Recordlength: 9
table description:
Key Start Len Index Type
1 10 4 multip. long NULL
update t1 set a=20 where b=10;
select * from t1 where b=10;
a b c
select * from t1 where b=21;
a b c
20 21 4121
20 21 9129
delete from t1 where b=21;
select * from t1 where b=21;
a b c
alter table t1 add column d char(20) as (concat(a,c));
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
create index i on t1 (d);
check table t1;
Table Op Msg_type Msg_text
test.t1 check status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
check table t1 quick;
Table Op Msg_type Msg_text
test.t1 check status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
check table t1 medium;
Table Op Msg_type Msg_text
test.t1 check status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
check table t1 extended;
Table Op Msg_type Msg_text
test.t1 check status OK
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 b 1 b A 999 NULL NULL YES BTREE
t1 1 i 1 d A 999 NULL NULL YES BTREE
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
delete from t1 where b=12;
analyze table t1;
Table Op Msg_type Msg_text
test.t1 analyze status OK
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 b 1 b A 998 NULL NULL YES BTREE
t1 1 i 1 d A 998 NULL NULL YES BTREE
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
optimize table t1;
Table Op Msg_type Msg_text
test.t1 optimize status OK
show keys from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 1 b 1 b A 998 NULL NULL YES BTREE
t1 1 i 1 d A 998 NULL NULL YES BTREE
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
repair table t1;
Table Op Msg_type Msg_text
test.t1 repair status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
repair table t1 quick;
Table Op Msg_type Msg_text
test.t1 repair status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
repair table t1 extended;
Table Op Msg_type Msg_text
test.t1 repair status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
repair table t1 use_frm;
Table Op Msg_type Msg_text
test.t1 repair warning Number of rows changed from 0 to 998
test.t1 repair status OK
select * from t1 where b=11;
a b c d
10 11 -5440 10-5440
update t1 set a=30 where b=11;
select * from t1 where b=11;
a b c d
select * from t1 where b=31;
a b c d
30 31 -5440 30-5440
30 31 -9880 30-9880
drop table t1;
#
# MDEV-11606 Server crashes in mi_make_key / sort_key_read
#
CREATE TABLE t1 (
pk BIGINT AUTO_INCREMENT,
col_date DATE NULL,
col_datetime DATETIME(1) NULL,
col_int TINYINT(13) UNSIGNED ZEROFILL NULL,
col_varchar VARBINARY(2222) NULL,
col_timestamp TIMESTAMP(2) NULL,
col_bit BIT(64) NOT NULL DEFAULT 0,
col_blob MEDIUMBLOB NULL,
col_dec DECIMAL(10,9) ZEROFILL NOT NULL DEFAULT 0,
col_time TIME(4) NULL,
col_year YEAR NOT NULL DEFAULT '1970',
col_char CHAR(129) NULL,
col_enum SET('','a','b','c','d','e','f','foo','bar') NULL,
vcol_dec DECIMAL(50,18) ZEROFILL AS (col_dec) VIRTUAL,
vcol_bit BIT(48) AS (col_bit) VIRTUAL,
vcol_char CHAR(224) AS (col_char) VIRTUAL,
vcol_datetime DATETIME(4) AS (col_datetime) VIRTUAL,
vcol_year YEAR AS (col_year) VIRTUAL,
vcol_varchar VARBINARY(356) AS (col_varchar) VIRTUAL,
vcol_blob MEDIUMBLOB AS (col_blob) VIRTUAL,
vcol_timestamp TIMESTAMP(5) AS (col_timestamp) VIRTUAL,
vcol_int BIGINT(46) AS (col_int) VIRTUAL,
vcol_time TIME(1) AS (col_time) VIRTUAL,
vcol_date DATE AS (col_date) VIRTUAL,
vcol_enum SET('','a','b','c','d','e','f','foo','bar') AS (col_enum) VIRTUAL,
UNIQUE(pk),
PRIMARY KEY(pk)
) ENGINE=MyISAM;
ALTER TABLE t1 ADD INDEX(col_enum,vcol_int);
ALTER TABLE t1 ADD INDEX(col_year);
DROP TABLE t1;
......@@ -2781,7 +2781,7 @@ int mi_repair_parallel(HA_CHECK *param, register MI_INFO *info,
del=info->state->del;
param->glob_crc=0;
/* for compressed tables */
max_pack_reclength= share->base.pack_reclength;
max_pack_reclength= MY_MAX(share->base.pack_reclength, share->vreclength);
if (share->options & HA_OPTION_COMPRESS_RECORD)
set_if_bigger(max_pack_reclength, share->max_pack_length);
if (!(sort_param=(MI_SORT_PARAM *)
......
......@@ -740,6 +740,7 @@ uchar *mi_alloc_rec_buff(MI_INFO *info, ulong length, uchar **buf)
else
length= info->s->base.pack_reclength;
length= MY_MAX(length, info->s->base.max_key_length);
length= MY_MAX(length, info->s->vreclength);
/* Avoid unnecessary realloc */
if (newptr && length == old_length)
return newptr;
......
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