Timestamped Performance

Which of the following is faster or equivalent? (capturing the most recent TIMESTAMP COLUMN journal entries)

SELECT UNIX_TIMESTAMP(`modified`) stamp FROM `some_table` HAVING stamp > 127068799 ORDER BY stamp DESC 

or

 SELECT UNIX_TIMESTAMP(`modified`) stamp FROM `some_table` WHERE UNIX_TIMESTAMP(`modified`) > 127068799 ORDER BY `modified` DESC 

or even another combination?

+4
source share
2 answers

Both are equal and not very good, since each row value must be converted to a timestamp

why not leave the date field as is and convert only a constant value?

 WHERE `modified` > FROM_UNIXTIME(127068799) 
+1
source

While modified being indexed, this one:

 SELECT UNIX_TIMESTAMP(`modified`) stamp FROM `some_table` WHERE modified > FROM_UNIXTIME(127068799) ORDER BY modified DESC 

- The best solution, since it is compatible and allows you to use the index on modified , unlike both of your queries.

+1
source

Source: https://habr.com/ru/post/1306352/


All Articles