Bug #121977 Assertion i < dict_index_get_n_unique(index) in innodb_rec_per_key() reading I_S.STATISTICS during ALTER TABLE
Description:
A query on INFORMATION_SCHEMA.STATISTICS with information_schema_stats_expiry = 0
asserts in a debug build when a concurrent in-place ALTER TABLE drops an index
and adds an index with the same name and fewer columns.
The query reads the key parts of the old index from the data dictionary, then
waits for the table metadata lock while the ALTER commits. It then asks InnoDB
for the cardinality of a key part that the new index does not have.
2026-11-29T10:35:49.164942Z 12 [ERROR] [MY-013183] [InnoDB] Assertion failure: ha_innodb.cc:17341:i < dict_index_get_n_unique(index) thread 0x16d04f000
Stack:
ut_dbg_assertion_failed
innodb_rec_per_key
innobase_get_index_column_cardinality
dd::info_schema::Table_statistics::read_stat_from_SE
dd::info_schema::Table_statistics::read_stat
Item_func_internal_index_column_cardinality::val_int
For a partitioned table the statistics come from the open table instead, and
the assertion is key_part_no < actual_key_parts in KEY::has_records_per_key()
(key.h), called from Table_statistics::read_stat_by_open_table().
How to repeat:
Run this MTR test on a debug build. It fails every time.
--source include/have_debug_sync.inc
CREATE TABLE p (id INT PRIMARY KEY, a INT, b INT, c INT, INDEX i (a, b, c));
INSERT INTO p VALUES (1,1,1,1),(2,2,2,2),(3,3,3,3);
SET SESSION information_schema_stats_expiry = 0;
--connect (con1, localhost, root,,)
SET DEBUG_SYNC = 'alter_table_inplace_before_commit SIGNAL ready WAIT_FOR go';
--send ALTER TABLE p DROP INDEX i, ADD INDEX i (a)
--connection default
SET DEBUG_SYNC = 'now WAIT_FOR ready';
--connect (con2, localhost, root,,)
SET SESSION information_schema_stats_expiry = 0;
--send SELECT INDEX_NAME, SEQ_IN_INDEX, CARDINALITY FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'p' ORDER BY 1, 2
--connection default
let $wait_condition = SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST
WHERE STATE = 'Waiting for table metadata lock' AND INFO LIKE 'SELECT INDEX_NAME%';
--source include/wait_condition.inc
SET DEBUG_SYNC = 'now SIGNAL go';
--connection con1
--reap
--connection con2
--reap
--disconnect con1
--disconnect con2
--connection default
SET DEBUG_SYNC = 'RESET';
DROP TABLE p;
Without DEBUG_SYNC, a loop of ALTER TABLE p DROP INDEX i, ADD INDEX i (a) and
back to (a, b, c) in one connection, and SELECTs of CARDINALITY from
INFORMATION_SCHEMA.STATISTICS in another, hits the assertion within seconds.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.039 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.