Optimal SQL Basics

Source: Internet
Author: User
There are three final objectives for writing SQL statements: 1. fast response time 2. Minimum CPU resources and 3 minimum I/O operations

Tips for promoting the best SQL

* From the I/O perspective, full table scanning is encouraged when indexes are meaningless.
If index scan accesses more blocks than full table scan, full table scan is very effective.
* If SQL contains subqueries, optimize them. in fact, they should be optimized first. if the subquery cannot be executed well, the primary query cannot be executed well. if a connection provides the subquery function, you should first try the connection method before trying to use the subquery method. note that subqueries are associated because they are expensive and frequently used by the CPU.

* Use not exists to replace not in the where condition of an SQL statement.
* Use the like operator with leading characters to replace the substr function. The like operator with leading characters (for example, 'a % 'in the compared value) will use indexes.
The substr function will invalidate the index, unless the database version is Oracle8i and a function-based index has been created.
-- Unfinished --

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.