A simple SELECT with ORDER BY on a table of 25 columns and 20 Lakh rows is slow, taking almost 40 seconds.
When ORDER BY is id (PK) the no issue takes around 0.003 seconds but when ORDER BY is on a datetime column with ON UPDATE CURRENT_TIMESTAMP() setting query takes around 40 seconds.
I have tried the following :
- SELECT 100 rows based on current_timestamp and then LEFT JOIN with the rest of the column.
- Index on current_timestamp but it fail once the post is updated.
- innodb_pool_size also tried
TABLE
ID | creat_time | access_time | title | value | more columns |
---|
- ID - int(11) AUTO_INCREMENT
- create_time - datetime
- access_time - datetime ON UPDATE CURRENT_TIMESTAMP()
- title - VARCHAR(100)
- value - LONGTEXT or TEXT
- more column - some of them are int(6), varchar(512), decimal(3,1) etc
QUERY IS :
SELECT *
FROM my_table
ORDER BY access_time
LIMIT 50;
also tried
SELECT A.*
FROM ( SELECT id
FROM my_table
ORDER BY access_time LIMIT 50
) AS PIE
LEFT JOIN my_table AS A ON (PIE.id = A.id);
LIMIT
?