1. Reduce I/O operations:
SELECT count ( case if empno>then 1 END) C1, Count empno<then 1 END) C2
from EMP;
2. Access via ROWID
SELECT ROWID,emp.* from emp
WHERE Rowid=chartorowid (' aaahw7aabaaamuiaaa ')
3. Use index unique scan
SELECT empno,ename from emp
WHERE empno=' 2000 '
4. Using and connecting symbols causes Oracle to ignore the use of the lasso, even if it is a unique index
SELECT empno,ename from emp
WHERE empno| | ename=' 2000naem '
You can use the index if you change it.
SELECT * from EMP
WHERE empno=+ ename=' dd '
5. Index Range Scan
SELECT * from EMP
WHERE empno<7000
6. the parse order of the WHERE conditional clause is from bottom to top
SELECT a.empno,b.dname from emp a,DEPTB
WHERE a.ename<' Clerk '
and A.deptno=B.deptno;
Takes 1.016 seconds
SELECT a.empno,b.dname from emp a,dept b
WHERE A.deptno=B.deptno
and A.ename<' clerk ';
time 0.813 seconds
7. Using wildcards will allow Oracle to not use the index
SELECT ename from emp
WHERE ename like '%c% '
should be changed into
SELECT ename from emp
WHERE ename like ' c% '
8. Finding the exact value with a unique index is the quickest, and the index range scan is more suitable for finding >=,<= data
SELECT A.ItemID
from Pt_sche_detail a,
Pt_post_role b
WHERE A.ItemID = b.taskid
and A.docid = 2281
and A.ItemID! = 1169015
and a.status! = 0
and B.posttype = 1
and B.roleid = 1022
and B.roletype = 1
The above statement is changed to:
SELECTA.ItemID
fromPt_sche_detail A,
Pt_post_role b
WHEREA.ItemID=B.taskid
andA.docid=2281
andA.ItemID!=1169015
andA.status!=0
andB.taskidinch
(SELECTItemid
fromPt_sche_detail Temp
WHERETemp.docid=2281
andrownum <= (SELECT COUNT (Itemid) fromPt_sche_detail TempWHERETemp.docid=2281))
andB.roleid=1022
andB.roletype=1
andB.posttype=1
Oracle+sql Optimization Examples