My Query looks like this
EXPLAIN SELECT
r.owner_id,
r.owner_address,
r.owner_platform,
r.updated_at
FROM some_owner_table as r
WHERE
r.updated_at > '2022-09-16 22:16:38.832'
ORDER BY
r.updated_at DESC LIMIT 200;
The result is
# id, select_type, table, partitions, type, possible_keys, key, key_len, ref, rows, filtered, Extra
'1', 'SIMPLE', 'r', NULL, 'range', 'INDEX_by_updated_at', 'INDEX_by_updated_at', '6', NULL, '1', '100.00', 'Using index condition'
However if we use a different date that, I think, increased the number of results we get :
'1', 'SIMPLE', 'r', NULL, 'ALL', 'INDEX_by_updated_at', NULL, NULL, NULL, '263', '37.64', 'Using where; Using filesort'
Using filesort
seems problematic in terms of performance. It's not longer using Using index condition
.
Is this how indexing really works or can we do something to further optimize our queries for this table?
EDIT: Table has 263 total rows.
EDIT: Create query:
CREATE TABLE `some_owner_table` (
`owner_id` bigint(20) NOT NULL,
`owner_address` bigint(20) NOT NULL,
`owner_platform` int(11) NOT NULL,
`updated_at` timestamp(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
PRIMARY KEY (`owner_id`,`owner_platform`),
KEY `INDEX_by_updated_at` (`updated_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;