Skip to content

Commit 80f6b22

Browse files
committed
MDEV-3870 - Valgrind warnings on OPTIMIZE MyISAM or Aria TABLE with disabled
keys Fixed that OPTIMIZE TABLE against MyISAM/Aria table may write uninitialized key root position for disabled keys.
1 parent 3a50a8c commit 80f6b22

File tree

6 files changed

+46
-8
lines changed

6 files changed

+46
-8
lines changed

mysql-test/r/myisam.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,6 +2522,17 @@ test.t1 check error Size of indexfile is: 1024 Should be: 2048
25222522
test.t1 check warning Size of datafile is: 14 Should be: 7
25232523
test.t1 check error Corrupt
25242524
DROP TABLE t1;
2525+
#
2526+
# MDEV-3870 - Valgrind warnings on OPTIMIZE MyISAM or Aria TABLE with
2527+
# disabled keys
2528+
#
2529+
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM;
2530+
INSERT INTO t1 VALUES (4),(3),(1),(0);
2531+
ALTER TABLE t1 DISABLE KEYS;
2532+
OPTIMIZE TABLE t1;
2533+
Table Op Msg_type Msg_text
2534+
test.t1 optimize status OK
2535+
DROP TABLE t1;
25252536
show variables like 'myisam_block_size';
25262537
Variable_name Value
25272538
myisam_block_size 1024

mysql-test/suite/maria/optimize.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,14 @@ OPTIMIZE TABLE t1;
66
Table Op Msg_type Msg_text
77
test.t1 optimize status OK
88
drop table t1;
9+
#
10+
# MDEV-3870 - Valgrind warnings on OPTIMIZE MyISAM or Aria TABLE with
11+
# disabled keys
12+
#
13+
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=Aria;
14+
INSERT INTO t1 VALUES (4),(3),(1),(0);
15+
ALTER TABLE t1 DISABLE KEYS;
16+
OPTIMIZE TABLE t1;
17+
Table Op Msg_type Msg_text
18+
test.t1 optimize status OK
19+
DROP TABLE t1;

mysql-test/suite/maria/optimize.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,13 @@ INSERT /*! IGNORE */ INTO t1 VALUES ('urxjxqvwabikpugvexxbxdpxjkeqiuhhuadbcuhoz
160160
check table t1;
161161
OPTIMIZE TABLE t1;
162162
drop table t1;
163+
164+
--echo #
165+
--echo # MDEV-3870 - Valgrind warnings on OPTIMIZE MyISAM or Aria TABLE with
166+
--echo # disabled keys
167+
--echo #
168+
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=Aria;
169+
INSERT INTO t1 VALUES (4),(3),(1),(0);
170+
ALTER TABLE t1 DISABLE KEYS;
171+
OPTIMIZE TABLE t1;
172+
DROP TABLE t1;

mysql-test/t/myisam.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,16 @@ CHECK TABLE t1;
17491749

17501750
DROP TABLE t1;
17511751

1752+
--echo #
1753+
--echo # MDEV-3870 - Valgrind warnings on OPTIMIZE MyISAM or Aria TABLE with
1754+
--echo # disabled keys
1755+
--echo #
1756+
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM;
1757+
INSERT INTO t1 VALUES (4),(3),(1),(0);
1758+
ALTER TABLE t1 DISABLE KEYS;
1759+
OPTIMIZE TABLE t1;
1760+
DROP TABLE t1;
1761+
17521762
#
17531763
# Check some variables
17541764
#

storage/maria/ma_check.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,10 +3119,8 @@ int maria_sort_index(HA_CHECK *param, register MARIA_HA *info, char *name)
31193119
for (key= 0,keyinfo= &share->keyinfo[0]; key < share->base.keys ;
31203120
key++,keyinfo++)
31213121
{
3122-
if (! maria_is_key_active(share->state.key_map, key))
3123-
continue;
3124-
3125-
if (share->state.key_root[key] != HA_OFFSET_ERROR)
3122+
if (maria_is_key_active(share->state.key_map, key) &&
3123+
share->state.key_root[key] != HA_OFFSET_ERROR)
31263124
{
31273125
index_pos[key]=param->new_file_pos; /* Write first block here */
31283126
if (sort_one_index(param,info,keyinfo,share->state.key_root[key],

storage/myisam/mi_check.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,10 +1944,8 @@ int mi_sort_index(HA_CHECK *param, register MI_INFO *info, char * name)
19441944
for (key= 0,keyinfo= &share->keyinfo[0]; key < share->base.keys ;
19451945
key++,keyinfo++)
19461946
{
1947-
if (! mi_is_key_active(info->s->state.key_map, key))
1948-
continue;
1949-
1950-
if (share->state.key_root[key] != HA_OFFSET_ERROR)
1947+
if (mi_is_key_active(info->s->state.key_map, key) &&
1948+
share->state.key_root[key] != HA_OFFSET_ERROR)
19511949
{
19521950
index_pos[key]=param->new_file_pos; /* Write first block here */
19531951
if (sort_one_index(param,info,keyinfo,share->state.key_root[key],

0 commit comments

Comments
 (0)