Skip to content

Commit 0a92ef4

Browse files
committed
MDEV-17223 Assertion `thd->killed != 0' failed in ha_maria::enable_indexes
MDEV-22500 Assertion `thd->killed != 0' failed in ha_maria::enable_indexes For MDEV-17223 the issue was an assert that didn't take into account that we could get duplicate key errors when enablling unique indexes. Fixed by not retrying repair in case of duplicate key error for this case, which avoids the assert. For MDEV-22500 I removed the assert, as it's not critical (just a way to find potential wrong code) and we will anyway get things logged in the error log if this happens. This case cannot triggered an assert in 10.3 but I verified that it would trigger in 10.5 and that this patch fixes it.
1 parent 6c3f1f6 commit 0a92ef4

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

mysql-test/suite/maria/repair.result

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,34 @@ SET max_session_mem_used=50000;
3131
REPAIR LOCAL TABLE t1 USE_FRM;
3232
REPAIR LOCAL TABLE t1;
3333
DROP TABLE t1;
34+
SET max_session_mem_used=default;
35+
36+
# MDEV-17223 Assertion `thd->killed != 0' failed in
37+
# ha_maria::enable_indexes
38+
#
39+
CREATE OR REPLACE TABLE t1 (c VARCHAR(1024) NOT NULL) ENGINE=Aria ROW_FORMAT FIXED;
40+
insert into t1 select char(seq) from seq_65_to_256;
41+
insert into t1 values ("a");
42+
ALTER TABLE t1 ADD PRIMARY KEY(c(67));
43+
ERROR 23000: Duplicate entry 'a' for key 'PRIMARY'
44+
select count(*) from t1;
45+
count(*)
46+
193
47+
drop table t1;
48+
49+
# MDEV-17223 Assertion `thd->killed != 0' failed in
50+
# ha_maria::enable_indexes
51+
#
52+
SET SESSION aria_sort_buffer_size=1023;
53+
Warnings:
54+
Warning 1292 Truncated incorrect aria_sort_buffer_size value: '1023'
55+
CREATE TABLE t2 (c TEXT,INDEX(c(1000))) ENGINE=Aria;
56+
INSERT INTO t2 select char(seq) from seq_65_to_255;
57+
SELECT COUNT(*) FROM t2;
58+
COUNT(*)
59+
191
60+
DROP TABLE t2;
61+
SET SESSION aria_sort_buffer_size=default;
62+
#
63+
# End of 10.3 tests
64+
#

mysql-test/suite/maria/repair.test

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# as memory usage is different compared to normal server.
44

55
--source include/not_embedded.inc
6+
--source include/have_sequence.inc
67

78
#
89
# MDEV-11539 test_if_reopen: Assertion `strcmp(share->unique_file_name,filename) || share->last_version' failed upon select from I_S
@@ -41,3 +42,35 @@ REPAIR LOCAL TABLE t1 USE_FRM;
4142
REPAIR LOCAL TABLE t1;
4243
--enable_result_log
4344
DROP TABLE t1;
45+
SET max_session_mem_used=default;
46+
47+
--echo
48+
--echo # MDEV-17223 Assertion `thd->killed != 0' failed in
49+
--echo # ha_maria::enable_indexes
50+
--echo #
51+
52+
CREATE OR REPLACE TABLE t1 (c VARCHAR(1024) NOT NULL) ENGINE=Aria ROW_FORMAT FIXED;
53+
insert into t1 select char(seq) from seq_65_to_256;
54+
insert into t1 values ("a");
55+
--error ER_DUP_ENTRY
56+
ALTER TABLE t1 ADD PRIMARY KEY(c(67));
57+
select count(*) from t1;
58+
drop table t1;
59+
60+
--echo
61+
--echo # MDEV-17223 Assertion `thd->killed != 0' failed in
62+
--echo # ha_maria::enable_indexes
63+
--echo #
64+
65+
SET SESSION aria_sort_buffer_size=1023;
66+
CREATE TABLE t2 (c TEXT,INDEX(c(1000))) ENGINE=Aria;
67+
--disable_warnings
68+
INSERT INTO t2 select char(seq) from seq_65_to_255;
69+
--enable_warnings
70+
SELECT COUNT(*) FROM t2;
71+
DROP TABLE t2;
72+
SET SESSION aria_sort_buffer_size=default;
73+
74+
--echo #
75+
--echo # End of 10.3 tests
76+
--echo #

storage/maria/ha_maria.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,13 +1958,19 @@ int ha_maria::enable_indexes(uint mode)
19581958
param->sort_buffer_length= THDVAR(thd,sort_buffer_size);
19591959
param->stats_method= (enum_handler_stats_method)THDVAR(thd,stats_method);
19601960
param->tmpdir= &mysql_tmpdir_list;
1961-
if ((error= (repair(thd, param, 0) != HA_ADMIN_OK)) && param->retry_repair)
1961+
1962+
/*
1963+
Don't retry repair if we get duplicate key error if
1964+
create_unique_index_by_sort is enabled
1965+
This can be set when doing an ALTER TABLE and enabling unique keys
1966+
*/
1967+
if ((error= (repair(thd, param, 0) != HA_ADMIN_OK)) && param->retry_repair &&
1968+
(my_errno != HA_ERR_FOUND_DUPP_KEY ||
1969+
!file->create_unique_index_by_sort))
19621970
{
19631971
sql_print_warning("Warning: Enabling keys got errno %d on %s.%s, "
19641972
"retrying",
19651973
my_errno, param->db_name, param->table_name);
1966-
/* This should never fail normally */
1967-
DBUG_ASSERT(thd->killed != 0);
19681974
/* Repairing by sort failed. Now try standard repair method. */
19691975
param->testflag &= ~T_REP_BY_SORT;
19701976
file->state->records= start_rows;

0 commit comments

Comments
 (0)