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

What problems will be caused by too long SQL statements in Mysql

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what problems will be caused by too long SQL sentences in Mysql". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what problems will be caused by too long SQL sentences in Mysql"?

Problems caused by too long Mysql SQL statements

I am now doing data statistics, the background database is using MYSQL. There is a common requirement to query the access PV of unordered users (the unique identity of the user is the user's mobile phone number)

The first way to write:

SELECT COUNT (1) FROM day_resinlog_2012_06_12 WHERE mobile_number NOT IN

(SELECT DISTINCT mobile_number FROM tbl_cartoon_order)

The second way to write: www.2cto.com

A List combination is obtained through SELECT DISTINCT mobile_number FROM tbl_cartoon_order, which splices the collection of mobile phone numbers into a string when the xxxxx in SELECT COUNT (1) FROM day_resinlog_2012_06_12 WHERE mobile_number NOT IN (xxxxx)

Comment: the first method of writing uses a subquery, which is relatively slow, which is generally the reason why we do not use it, and why we choose the second way of writing.

On the surface, there is no problem with the second way of writing, but in fact, there is a potential risk that if we order millions of mobile phone numbers, it may cause the server to report an error. Because if a SQL is too long to exceed the amount of max_allowed_packet in the MYSQL server configuration file (my.ini), it will report an error. The solution is to change the amount of max_allowed_packet.

At this point, I believe you have a deeper understanding of "what problems will be caused by too long SQL statements in Mysql?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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