Here’s a little mystery - I’ll let the code speak for itself:
mysql> select max(id) from mytable;
±----------+
| max(id) |
±----------+
| 577711424 |
±----------+
1 row in set (0.00 sec)
mysql> select now(), created from mytable where id in (577711424);
±--------------------±--------------------+
| now() | created |
±--------------------±--------------------+
| 2015-05-12 12:04:53 | 2015-05-12 12:03:24 |
±--------------------±--------------------+
1 row in set (0.00 sec)
Now for the kicker:
mysql> select now(), created from mytable where id in (select max(id) from mytable);
±--------------------±--------------------+
| now() | created |
±--------------------±--------------------+
| 2015-05-12 12:05:10 | 2015-05-12 12:05:10 |
±--------------------±--------------------+
1 row in set (6 min 18.60 sec)
mysql> explain select now(), created from mytable where id in (select max(id) from mytable);
±—±-------------------±------±-----±--------------±-----±--------±-----±----------±-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
±—±-------------------±------±-----±--------------±-----±--------±-----±----------±-----------------------------+
| 1 | PRIMARY | mytable | ALL | NULL | NULL | NULL | NULL | 292257304 | Using where |
| 2 | DEPENDENT SUBQUERY | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Select tables optimized away |
±—±-------------------±------±-----±--------------±-----±--------±-----±----------±-----------------------------+
2 rows in set (0.00 sec)