当前位置:网站首页>Date of SQL optimization_ Format() function

Date of SQL optimization_ Format() function

2022-06-11 20:08:00 A man who didn't want to be named

There is a problem in the online environment today , Front end interface request timed out , I immediately ran to the formal environment to run the request timeout sql, Shock me , It's running well 30 More than a second , This is not acceptable. , We have to optimize it quickly , But there is something left to look up and down , No problem! , therefore , Asked the great God of our group , He saw the problem at a glance , The problem is DATE_FORMAT() This function , So , I want to make a record , I hope you don't step on the pit .

If the amount of data is small , Application DATE_FORMAT() Performance is not affected , But once the amount of data is large After that , There will be performance problems slowly , This is also because the test environment did not find out , This problem occurs in the formal environment .

For demonstration : I put it in my watch Tens of millions of data ,

  The data structure is like this , I want to find out regist_date yes 2018 Years of data

I'll fix this sql:

when :

After optimization, execute :

 

Performance is flying :

Why , because DATE_FORMAT Function will invalidate the index , Therefore, this function is not recommended for large data volume .

原网站

版权声明
本文为[A man who didn't want to be named]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206112000416457.html