Problems caused by too long Mysql SQL statements

Source: Internet
Author: User

Mysql SQL statements are too long and cause problems. I am doing data statistics now. MYSQL is used in the background database. There is a common requirement to query the PV of unordered users (the user's unique ID is the user's mobile phone number); the first statement is: select count (1) FROM nation WHERE mobile_number not in (select distinct mobile_number FROM tbl_cartoon_order); Method 2: Use select distinct mobile_number FROM tbl_cartoon_order to obtain a List <String> combination, concatenate the collection of the obtained mobile phone numbers into a string. When select count (1) FROM day_resinlog_2012_06_12 WHERE mobile_number not in (xxxxx) IN xxxxx, comment: the first method uses subquery, this process is slow. We don't need it because we chose the second method. There is no problem with the second method on the surface, but there is also a potential risk. If we order millions of mobile phone numbers, the server may report an error. If an SQL statement is too long and exceeds the max_allowed_packet value in the MYSQL server configuration file (my. ini in windows), an error is returned. The solution is to change the max_allowed_packet volume. Author: lovemelovemycode

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.