oracle| Performance | optimization
17. Use table alias (alias)
When you connect multiple tables in an SQL statement, use the alias of the table and prefix the alias with each column. This allows you to reduce parsing time and reduce syntax errors caused by column ambiguity.
(Translator Note: column ambiguity means that because different tables in SQL have the same column name, the SQL parser cannot determine the attribution of this column when the column appears in the SQL statement)
18. Replace in with exists
In many queries based on the underlying table, it is often necessary to join another table in order to satisfy one condition. In this case, using EXISTS (or not EXISTS) usually increases the efficiency of the query.
Low efficiency:
SELECT *
From EMP (base table)
WHERE EMPNO > 0
and DEPTNO in (SELECT DEPTNO
From DEPT
WHERE LOC = ' Melb ')
Efficient:
SELECT *
From EMP (base table)
WHERE EMPNO > 0
and EXISTS (SELECT ' X '
From DEPT
WHERE DEPT. DEPTNO = EMP. DEPTNO
and LOC = ' Melb ')
(Translator: Relatively speaking, replacing not in with not exists will significantly increase efficiency, as noted in the next section)
19. Use NOT exists instead of in
In a subquery, the NOT IN clause performs an internal sort and merge. In either case, not in is the least efficient (because it performs a full table traversal of the table in the subquery). In order to avoid using not in, we can rewrite it as an outer join (Outer joins) or not EXISTS.
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.