So I recently reimported my ROCKSDB database from a backup, with a fresh bulk_load and all inserted in primary key order. Took some time, but now it’s fresh and shiny ;).
However, without having changed anything in the application that calls the database, unfortunately a query that is used a lot in background processing workers, now takes 50s instead of 1s.
I debugged it and it turns out that the following query always uses a table scan. Even though I force the proper index, explain shows me that no index is used.
SELECT name, id, FROM foo_names FORCE INDEX (name) where name in (10.000 items);
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
1 SIMPLE foo_names NULL ALL name NULL NULL NULL 301584577 50.00 Using where
I guess somehow it decides that > 10.000 items or so, the table scan is faster. But it’s certainly not.
I find it weird that even though I force a index, it still doesn’t use it.
I did also set the max_seeks_for_key=1000
to debug, but this does not change anything.
How can I force force to use the index?
CREATE TABLE `foo_names` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(768) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
) ENGINE=ROCKSDB AUTO_INCREMENT=303679574 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin ROW_FORMAT=FIXED |
Server version: 8.0.34-26 Percona Server (GPL), Release 26, Revision 0fe62c85