Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of time-based query Optimization in mysql

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the method of mysql query optimization by time, I hope you will gain a lot after reading this article, let's discuss it together!

Mysql time query optimization method: 1, [register_time] field is datetime type, converted to date matching, need to query out all rows for filtering; 2, you can use the [register_time] field to establish an index, the query is very fast.

Mysql query optimization method by time:

For example, the query of newly registered users yesterday can be written in the following two ways:

EXPLAINselect * from chess_user u where DATE_FORMAT (u.registerless timekeeping% YMY% mMUE% d') = '2018-01-25 from chess_user u where u.register_time BETWEEN' 2018-01-25 0000VV 00' and '2018-01-25 23V 59from chess_user 59'

The register_time field is of type datetime. If it is converted to date matching, all rows need to be queried and filtered. And the second way of writing, you can use to build an index on the register_time field, the query is very fast!

Attached date conversion function

DECLARE yt varchar (10); # yesterday's DECLARE yt_bt varchar (19); # yesterday's start time DECLARE yt_et varchar (19); # yesterday's end time # set the variable SET yt=DATE_FORMAT (DATE_ADD (now (), INTERVAL-1 day),'% Ymuri% mmi% d'); SET yt_bt=DATE_FORMAT (DATE_ADD (now (), INTERVAL-1 day),'% Y-%m-%d 00lv 0000') SET yt_et=DATE_FORMAT (DATE_ADD (now (), INTERVAL-1 day),'% Y-%m-%d 23 day 59 INTERVAL 59'). After reading this article, I believe you have some understanding of the time query optimization method of mysql. Want to know more about it. Welcome to follow the industry information channel. Thank you for your reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report