oracle sql tunning 15 --常用改寫
改寫的目的是為了縮短語句執行時間,通常第2種方法比第一種好
1.having vs where
(1)select owner,count(*) from all_objects group by owner having wner='SYS'
time:44.156 seconds cost:250
(2)select owner,count(*) from all_objects WHERE wner='SYS' group by owner
time:2.985 seconds cost:244
2.minus vs not in
測試表:
drop table test1;
create table test1 as select owner,object_id,object_name from all_objects
drop table test2;
create table test2 as select owner,object_id,object_name from all_objects where object_id>2000
(1)
select object_id
from test1
minus
select object_id
from test2
time:0.688seconds cost:631
(2)
select distinct a.object_id from test1 a where a.object_id not in (select object_id from test2)
time:0.219seconds cost:592
3.or vs union
(1)select * from test1 where wner = 'SYS' OR wner='HR' or wner='SCOTT'
time:0.094 seconds cost:109
(2)
SELECT * FROM TEST1 WHERE wner='SYS'
UNION
SELECT * FROM TEST1 WHERE wner='HR'
UNION
SELECT * FROM TEST1 WHERE wner='SCOTT'
time:1.281 seconds cost:329
4.or vs in
(1)select * from test1 where wner = 'SYS' OR wner='HR' or wner='SCOTT'
time:0.094 seconds cost:109
(2)select * from test1 where owner in ('SYS','HR','SCOTT')
time:0.016 seconds cost:109
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15720542/viewspace-664827/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle sql tunning all hintsOracleSQL
- Oracle case when改寫SQLOracleSQL
- sql改寫SQL
- 關閉sql tunningSQL
- oracle performance tunningOracleORM
- SQL TUNNING 注意事項SQL
- SQL改寫優化SQL優化
- oracle performance tunning(1)OracleORM
- oracle performance tunning(2)OracleORM
- oracle performance tunning(3)OracleORM
- oracle performance tunning(4)OracleORM
- oracle performance tunning(5)OracleORM
- oracle performance tunning(6)OracleORM
- oracle performance tunning(7)OracleORM
- oracle performance tunning(8)OracleORM
- oracle performance tunning(9)OracleORM
- oracle performance tunning(10)OracleORM
- Oracle 常用SQLOracleSQL
- DB2 SQL改寫DB2SQL
- 一條SQL的改寫SQL
- creating indexing for SQL tunningIndexSQL
- MySQL的SQL等價改寫MySql
- 改寫不走索引的SQL索引SQL
- ORACLE 常用的SQLOracleSQL
- SQL常用的特殊寫法SQL
- Oracle Rownum分頁改寫Oracle
- Oracle SQL寫法OracleSQL
- oracle常用SQL查詢OracleSQL
- oracle常用SQL語句OracleSQL
- Oracle常用監控SQLOracleSQL
- Oracle DBA常用sql分享OracleSQL
- oracle 維護常用SQLOracleSQL
- Oracle 常用SQL筆記OracleSQL筆記
- 參考SQL Tunning Adviser進行SQL優化SQL優化
- Oracle到PostgreSQL等價改寫OracleSQL
- ORACLE之常用FAQ:SQL&PL/SQLOracleSQL
- SQL 改寫系列七:謂詞移動SQL
- SQL改寫的方法,select group by sumSQL