InnoDB internally stores the indexes of a table in SYS_INDEXES, ordered by the internal hidden key dict_index_t::id. Ever since InnoDB started to support ADD INDEX without rebuilding the whole table (first, in the InnoDB Plugin for MySQL 5.1), it became possible for the internal ordering of InnoDB dict_table_t::indexes to differ from the ordering of TABLE::key_info. To solve this inconsistency, an additional data structure INNOBASE_SHARE::idx_trans_tbl was added to map SQL key numbers to InnoDB indexes. But, as reported in
MDEV-6443, there appear to be some glitches when it comes to updating this mapping.
We should remove the INNOBASE_SHARE::idx_trans_tbl, and instead change the dict_table_t::indexes to be sorted not by dict_index_t::id but according to the same rules as TABLE::keys.