I've got a table:
CREATE TABLE `myTable` (
`a` DECIMAL(8,3) NULL DEFAULT NULL,
`b` INT(11) NULL DEFAULT NULL,
`name` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_general_ci',
`id` INT(11) NOT NULL AUTO_INCREMENT,
`plus` VARCHAR(100) NOT NULL DEFAULT 't' COLLATE 'utf8_unicode_ci',
PRIMARY KEY (`id`),
INDEX `myKey` (`a`, `b`, `name`)
)
COLLATE='utf8_unicode_ci'
ENGINE=InnoDB
AUTO_INCREMENT=2416682;
I run a query:
SELECT * FROM myTable
order by a, b, name
limit 10000, 8 ;
It is very slow, takes about two seconds.
If I run an explain, it gives back this:
'id' => 1,
'select_type' => 'SIMPLE',
'table' => 'myTable ',
'partitions' => NULL,
'type' => 'ALL',
'possible_keys' => NULL,
'key' => NULL,
'key_len' => NULL,
'ref' => NULL,
'rows' => 1759263,
'filtered' => 100.00,
'Extra' => 'Using filesort',
Now if I set the limit to a lower value, it becomes very fast and explain says it uses myKey:
SELECT * FROM myTable
order by a, b, name
limit 1000, 8 ;
explain:
'id' => 1,
'select_type' => 'SIMPLE',
'table' => 'myTable',
'partitions' => NULL,
'type' => 'index',
'possible_keys' => NULL,
'key' => 'myKey',
'key_len' => '779',
'ref' => NULL,
'rows' => 1008,
'filtered' => 100.00,
'Extra' => NULL,
What can I do to make the select faster when the limit has high numbers?
I'm suprised the key is not used all the time, independent of the limit value. Is this normal?
MySQL version is 5.7.20-log.
Thanks