Created
June 15, 2011 07:59
-
-
Save tinnet/1026668 to your computer and use it in GitHub Desktop.
mysql timestamp fun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE `mails` ( | |
`id` bigint(20) NOT NULL auto_increment, | |
`email` varchar(250) NOT NULL, | |
`type` char(6) NOT NULL, | |
`time` int(11) NOT NULL, | |
PRIMARY KEY (`id`), | |
UNIQUE KEY `email` (`email`), | |
KEY `time` (`time`), | |
KEY `type` (`type`) | |
) ENGINE=MyISAM; | |
/* old query */ | |
explain SELECT email, type, time FROM mails WHERE DATE(FROM_UNIXTIME(time)) > DATE_SUB(NOW(), INTERVAL 2 DAY); | |
/* new query */ | |
explain SELECT email, type, time FROM mails WHERE time > UNIX_TIMESTAMP(NOW() - INTERVAL 2 DAY); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment