2011年 01月 22日

MySQL 5.0 の TIMESTAMP 型の2038年問題 (インデックスを貼るだけでひけなくなる)

TIMESTAMP 型のカラムにインデックスはったら何もひけなくなるということに遭遇した。手元の MySQL 5.1.53 だと再現しないので、一部のバージョンにおけるバグかもしれない。2038年問題におけるX-dayは1/19なのに、なぜか 1/1 が終わった時点で invalid になっていた。面倒なのでよく調べていない……

Your MySQL connection id is 3495640
Server version: 5.0.22

(nobody@192.168.2.155) [log]> select * from log where created < '2038-01-02 00:00:01' limit 1;
Empty set, 2 warnings (0.02 sec)

(nobody@192.168.2.155) [log]> show warnings;
+---------+------+-------------------------------------------------------------------------------+
| Level   | Code | Message                                                                       |
+---------+------+-------------------------------------------------------------------------------+
| Warning | 1292 | Incorrect datetime value: '2038-01-02 00:00:01' for column 'created' at row 1 |
| Warning | 1292 | Incorrect datetime value: '2038-01-02 00:00:01' for column 'created' at row 1 |
+---------+------+-------------------------------------------------------------------------------+
2 rows in set (0.03 sec)