if I have a index for (col1, col2, col3, col4), my query put col1 and col2 in the query where clause and force MySQL to use the above index. Would my query result be sorted by col3 and col4 automatically?
Table is something like this:
CREATE TABLE IF NOT EXISTS `jobs` (
`job_id` varchar(36) NOT NULL,
`job_status` varchar(30) NOT NULL,
`created_at` datetime NOT NULL,
`lease_date` datetime,
`priority` int NOT NULL,
PRIMARY KEY(`job_id`),
INDEX `job_status_priority_lease_date` (`job_status`, `priority`, `lease_date`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
The full query I want to do is the following:
select * from jobs use index (job_status_priority_lease_date)
where status="IN_PROGRESS"
and priority=0
limit 100
Would my query result be sorted by the lease_date
automatically? Because of some limitation, I cannot use the order by
statement.
EXPLAIN {query}
to show which index was used and how.lease_date
sorted.