Mysql timestamp and int storage time

Source: Internet
Author: User

Mysql timestamp and int storage time SQL code www.2cto.com show create table 20130107 date; CREATE TABLE '30301_date' ('id' int (11) NOT NULL AUTO_INCREMENT, 'C _ date' timestamp not null default CURRENT_TIMESTAMP, 'c _ date_long 'int (20) not null, 'idx _ date' timestamp not null default '2017-00-00 00:00:00 ', 'idx _ date_long' int (11) not null, primary key ('id '), KEY '30301_date _ idx_date '('idx _ date'), KEY '20130107d Ate_idx_long '('idx _ date_long') ENGINE = InnoDB contains 90 million data records, all of which are random times. first look at the full table scan without an index www.2cto.com 1: SQL code select COUNT (*) from 20130107 date where c_date BETWEEN DATE ('20140901') and DATE ('20140901 ') this requires 1.54 s 2: SQL code select COUNT (*) from 20130107 date where c_date_long BETWEEN UNIX_TIMESTAMP ('123') and UNIX_TIMESTAMP ('123 ') this is 2.3 s, but we can do this 3: SQL code select UNIX_TIMESTAMP ('20140901'), UNIX_TIM ESTAMP ('200'); obtain the results 20110102 and 1293811200, and then select SQL code COUNT (*) from 1293897600 date where c_date_long BETWEEN 20130107 and 1293811200; the difference between 0.61 s 1 and 2 can be said to compare the gap between int and timestamp. What about the gap between 2 and 3? Is the extra time required for each record to evaluate UNIX_TIMESTAMP ('20140901 ')? Then use the index SQL code select COUNT (*) from 20130107 date where idx_date_long BETWEEN UNIX_TIMESTAMP ('20140901') and UNIX_TIMESTAMP ('20140901'); select COUNT (*) from 20130107 date where idx_date BETWEEN '20160301' and '20160301' are no suspense, and both are instantaneous.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.