Database SQL Performance Optimization (I): Database SQL Performance Optimization
Substr (hbs_bh, 5400) = '000000', optimization processing: hbs_bh like '000000' trunc (sk_rq) = trunc (sysdate), optimization processing: sk_rq> = trunc (sysdate) and sk_rq <trunc (sysdate + 1)
Fields with explicit or implicit operations cannot be indexed, for example:
Ss_df + 20> 50, optimization processing: ss_df> 30 'X' | hbs_bh> 'x5400021452 ', optimization processing: hbs_bh> '000000' sk_rq + 5 = sysdate, optimization processing: sk_rq = sysdate-5 hbs_bh = 5401002554, optimization: hbs_bh = '000000', note: this condition for hbs_bh implicit to_number conversion, because the hbs_bh field is bytes type.
When multiple fields in the table are included in the condition, indexes cannot be performed. For example, ys_df> cx_df cannot be optimized. qc_bh | kh_bh = '20170101: qc_bh = '000000' and kh_bh = '000000'
DELETE FROM EMP E WHERE E.ROWID > (SELECT MIN(X.ROWID) FROM EMP X WHERE X.EMP_NO = E.EMP_NO)
SELECT TAB_NAME FROM TABLES WHERE (TAB_NAME,DB_VER) = ( SELECT TAB_NAME,DB_VER FROM TAB_COLUMNS WHERE VERSION = 604)
(Efficient) SELECT * from emp (basic table) where empno> 0 and exists (SELECT 'x' from dept where dept. DEPTNO = EMP. deptno and loc = 'melb ')
(Inefficient) SELECT * from emp (basic table) where empno> 0 and deptno in (select deptno from dept where loc = 'melb ')
Select executions, DISK_READS, BUFFER_GETS, ROUND (BUFFER_GETS-DISK_READS)/BUFFER_GETS, 2) Hit_radio, ROUND (DISK_READS/EXECUTIONS, 2) Reads_per_run, SQL _TEXT FROM V $ SQLAREA WHERE EXECUTIONS> 0 AND BUFFER_GETS> 0 AND (BUFFER_GETS-DISK_READS)/BUFFER_GETS <0.8 ORDER BY 4 DESC;
(Inefficient): select distinct DEPT_NO, DEPT_NAME from dept d, emp e where d. DEPT_NO = E. DEPT_NO
(Efficient): SELECT DEPT_NO, DEPT_NAME from dept d where exists (SELECT 'x' from emp e where e. DEPT_NO = D. DEPT_NO );
Inefficient: SELECT... From dept where sal * 12> 25000; efficiency: SELECT... From dept where sal> 25000/12;
Efficient: SELECT LOC_ID, LOC_DESC, region from location where LOC_ID = 10 union select LOC_ID, LOC_DESC, region from location where region = "MELBOURNE"
Inefficient: SELECT LOC_ID, LOC_DESC, region from location where LOC_ID = 10 or region = "MELBOURNE"
Inefficient: SELECT ACCT_NUM, BALANCE_AMT FROM DEBIT_TRANSACTIONS WHERE TRAN_DATE = '31-DEC-95 'union select ACCT_NUM, BALANCE_AMT FROM DEBIT_TRANSACTIONS WHERE TRAN_DATE = '31-DEC-95'
Efficient: SELECT ACCT_NUM, BALANCE_AMT FROM DEBIT_TRANSACTIONS WHERE TRAN_DATE = '31-DEC-95 'union all select ACCT_NUM, BALANCE_AMT FROM DEBIT_TRANSACTIONS WHERE TRAN_DATE = '31-DEC-95'
To improve the efficiency of the group by statement, you can filter out unnecessary records before group by. The following two queries return the same results, but the second query is much faster.
Inefficient: select job, AVG (SAL) from emp group by job having job = 'President 'or job = 'manager'
Efficient: select job, AVG (SAL) from emp where job = 'President 'or job = 'manager' GROUP by JOB
Public Account recommendation:
Public Account: voaenglish
No.: voahk01
Follow the QR code long. Thank you.