SQL Big Data query cautious with order by

Source: Internet
Author: User

Today, in a table in SQL queries, the query takes at least 20 seconds, the data is 620000 rows, and the SQL statement is as follows:

Test one: Use ORDER BY

Simply query 0, 10 rows of data, time consuming 27.888s

Select A.id,a.county_id,a.county_name,a.town_id,a.town_name,a.village_id,a.village_name,b.province as Province_ Name,b.name as City_name from place a left join City B in A.city_id=b.code where a.id is isn't null order by A.VILLAGE_ID as C Limit 0, 10

Test two: Do not use ORDER by

Select A.id,a.county_id,a.county_name,a.town_id,a.town_name,a.village_id,a.village_name,b.province as Province_ Name,b.name as City_name from place a left join City B on A.city_id=b.code where a.id are not null limit 0, 10

Also query 0, 10 rows of data, time consuming 0.084s

The above is for reference only, more detailed optimization is needed when the data is larger

SQL Big Data query cautious with order by

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.