MAX(id) function in query with indexed condition I have a table

create table test
(
  id int auto_increment,
  createdAt TIMESTAMP not null,
  primary key (id)
);
create index createdAt
  on test (createdAt);


And here is my query

SELECT MAX(id) FROM test WHERE DATE(createdAt) &lt;= '2020-02-07';


Explain says Using where; Using index
But slow query log says 1 - 10+ seconds.

Important notice: Old rows with createdAt &lt; NOW() - 1 MONTH periodically removed by separate cron job. Average rows count 100k-10m.

As I understand, MAX() function compares each row, so results are so volatile.

Question: Is there any possible optimizations for such aggregation function?
DATE(), not MAX() is the villain...

DATE(createdAt) &lt;= '2020-02-07' is not "sargable".

This has the equivalent effect, and can use INDEX(created_at):  created_at &lt;= '2020-02-07'.  Yes, that works for datatypesDATE,DATETIME, andTIMESTAMP`.