Bad SQL statements

Source: Internet
Author: User

A bad SQL statement colleague sent an SQL statement, saying that this SQL statement occupies a large amount of server disk space during execution, which is about 10 Gb, and the efficiency is ultra-slow SELECT MIN (order_id ), MAX (order_id) FROM (select *, date (order_creation_date) create_date from orders where (1 = 1) AS t1 1 is a bad SQL statement, select * from table_name is definitely not allowed. 2 at the beginning, I didn't understand what this SQL is for. Why should I query data from this table? Select *, date (order_creation_date) create_date from orders where (1 = 1) as a nested table. 3. Why does a temporary table exist in the middle of the disk space during the query process, so the memory cannot store so much data and the data is copied to the disk, generally, a similar # SQL _ *** is generated under/tmp _***. MYD, # SQL _***. A file like MYI is actually a myisam table. This process wastes time and affects performance. Consult a colleague to query the maximum and minimum values of order_id. After reading the structure of the orders table, the order_id of orders is the auto-incrementing primary key, which is simple. Rewrite the following select max (order_id) and min (order_id) from orders order_id is the auto-incrementing primary key, the index has been created and is ordered. Therefore, the maximum and minimum values of the max min composite function are very fast.

Related Article

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.