Oracle performance SQL Tuning

Source: Internet
Author: User
We recommend that you use the following methods and Suggestions after testing!

17.Use the table alias (alias)

When connecting multiple tables in an SQL statement, use the table alias and prefix the alias on each column. in this way, the parsing time can be reduced and the syntax errors caused by column ambiguity can be reduced.

 

(Note: ColumnAmbiguity refers to the SQLDifferent tables have the same columnName,When SQLThe column appears in the statement.SQLThe parser cannot determine this column)

 

18.Use existsReplace in

In many basic table-based queries, to meet one condition, you often need to join another table. in this case, using exists (or not exists) usually improves the query efficiency.

 

Inefficiency:

Select *

From EMP (basic table)

Where empno> 0

And deptno in (select deptno

From Dept

Where loc = 'melb ')

Efficient:

Select *

From EMP (basic table)

Where empno> 0

And exists (select 'x'

From Dept

Where Dept. deptno = EMP. deptno

And loc = 'melb ')

 

 

 (Press:Relatively speaking,Use not existsReplace not inIt will significantly improve efficiency,As described in the next section)

 

 

19.Use not existsReplace not in

In a subquery, the not in Clause executes an internal sorting and merging. in either case, not in is the most inefficient (because it executes a full table traversal for the table in the subquery ). to avoid the use of not in, we can rewrite it into an outer join (outer joins) or not exists.

 

For example:

Select...

From EMP

Where dept_no not in (select dept_no

From Dept

Where dept_cat = 'A ');

 

To improve efficiency, rewrite it:

 

(Method 1: efficient)

Select ....

From emp a, DEPT B

Where a. dept_no = B. Dept (+)

And B. dept_no is null

And B. dept_cat (+) = 'A'

 

 

(Method 2: most efficient) --- available

Select ....

From EMP E

Where not exists (select 'x'

From dept d

Where D. dept_no = E. dept_no

And dept_cat = 'A ');

 

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.