C
C
corpsepk2016-10-03 13:42:10
MySQL
corpsepk, 2016-10-03 13:42:10

How to speed up/cache the "SELECT MAX(updated_at) FROM `table`" query at the DB level?

mysql table:

CREATE TABLE `db`.`table` ( 
    `id` INT(11) NOT NULL AUTO_INCREMENT ,
    `updated_at` DATETIME NOT NULL ,
    `name` VARCHAR(255) NOT NULL ,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB;

There is a cache that dies when the result of a query changes.
SELECT MAX(updated_at) FROM `table`
Is there a way at the DB level to speed up / cache this query?
Without creating:
- additional tables (and creating a trigger)
- an index on `updated_at` (which would be needed only for this query)
Perhaps there is some native and very simple solution?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
romy4, 2016-10-03
@corpsepk

You can create an insert/delete trigger in a table and create a separate field with the maximum value for the field that will change upon insertion/deletion.

S
Smithson, 2016-10-03
@Smithson

Have you created an index on the field updated_at?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question