A high-quality SQL starts with asking questions (notes)

Source: Internet
Author: User

First, the purpose of SQL writing is to solve the problem, so only to understand the problem to solve, to write more efficient SQL statements, to gracefully solve the problem, to get more happiness!

When writing an SQL statement, think like an optimizer, ask yourself these questions, and believe that long-time accumulation results will make your SQL efficient and elegant.

1) What tables are needed to get all the data you need?

2) Are there any tables that are partitioned? If so, how are partitions defined?

3) What are the columns for each table?

4) What are the indexes that can be referenced in each table?

5) What are the statistics for each table and the columns and indexes in it?

6) Are there histogram information on some columns? (This thing doesn't know what it is)

Through the above questions. and the rational placement of the search conditions before and after the order, to a certain extent less detours, improve the efficiency of SQL

For example, when using multiple and, put the most likely false first, if you use or to put the most likely to be true in front, as much as possible to use and less use OR and so on

A high-quality SQL starts with asking questions (notes)

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.