Performance Comparison Between datediff and date_format

Source: Internet
Author: User

Recently, there is a function that needs to query data in the database for a certain day, and the data time is in the timestamp format. In this way, when I query data, there are two options:

Select * From tuples where datediff (created_on, '2017-07-09 ') = 0
Select * From tuples where date_format (created_on, '% Y-% m-% D') = '2017-07-09'

The amount of data in the database is large, with more than 4 million entries. Compare the execution time

 

 

Showing rows 0-29 (175 total, query took0.0009Sec)
Showing rows 0-29 (175 total, query took0.0012Sec)

 

From the results, they are quite different, and both are acceptable. Datediff seems to be more efficient!

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.