Technical Analysis on Oracle SQL statement Optimization

Source: Internet
Author: User

IN Operator

SQL statements written IN are easy to write and understand, which is suitable for modern software development.

However, SQL statements using IN always have low performance. The following differences exist between SQL statements using IN and SQL statements without IN:

ORACLE tries to convert it to the join of multiple tables. If the conversion fails, it first executes the subquery IN and then queries the outer table records, if the conversion is successful, multiple tables are directly connected for query. It can be seen that at least one conversion process is added to SQL statements using IN. General SQL statements can be converted successfully, but SQL statements that contain grouping statistics cannot be converted.

Recommended Solution: avoid using the IN operator IN business-intensive SQL statements.

Not in Operator

This operation is not recommended for strong columns because it cannot apply table indexes.

Recommended Solution: use not exists or (the outer join + is null) instead.

 <> Operator (not equal)

The non-equals operator will never use the index, so the processing of it will only generate a full table scan.

Recommended Solution: use operations with the same functions, such

A <> 0 to a> 0 or a <0

A <> ''To a>''

Is null or is not null (whether the field is null)

Generally, indexes are not used to determine whether a field is null, because the B-tree index does not have a null index.

Recommended solution:

Use other operations with the same function, such

Change a is not null to a> 0 or a>.

Fields are not allowed to be empty, but a default value is used to replace null values. For example, status fields in the application for expansion cannot be empty. The default value is application.

Create a bitmap index (partition-based tables cannot be created, and bitmap indexes are difficult to control. If too many fields are indexed, performance will be degraded, and data block locks will be added when multiple users perform update operations)

> And <operator (greater than or less than operator)

If the value is greater than or less than the operator, you do not need to adjust it. Because it has an index, index search is used, but in some cases it can be optimized. For example, a table has 1 million records, for A numeric field A, 0.3 million records A = 3. Therefore, the effect of executing A> 2 and A> = 3 is very different, because ORACLE will first find the record index of 2 and then compare it, when A> = 3, ORACLE directly finds the record Index = 3.

LIKE Operator

The LIKE operator can be used for wildcard queries. The wildcard combinations in the LIKE operator can be used for almost any queries. However, poor use may result in performance problems, for example, LIKE '% 100' does not reference the index, while LIKE 'x5400%' references the range index. An actual example: the user ID following the Business ID in the YW_YHJBQK table can be used to query the Business ID YY_BH LIKE '% 100'. This condition will generate a full table scan, if you change to YY_BH LIKE 'x5400% 'OR YY_BH LIKE 'b5400%', the index of YY_BH will be used to query the two ranges, and the performance will be greatly improved.

  1. Cloud database technology is becoming increasingly popular among various vendors
  2. Oracle releases new Oracle hosted CRM R16 features
  3. Four skills for middle-stage Oracle Database Management

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.