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 case when改寫SQLOracleSQL
- 關閉sql tunningSQL
- Oracle 常用SQL筆記OracleSQL筆記
- DB2 SQL改寫DB2SQL
- Oracle Rownum分頁改寫Oracle
- Oracle DG運維常用SQLOracle運維SQL
- 【BLOCK】Oracle 塊管理常用SQLBloCOracleSQL
- 【LOB】Oracle Lob管理常用sqlOracleSQL
- MySQL的SQL等價改寫MySql
- Oracle到PostgreSQL等價改寫OracleSQL
- 【ORACLE】Oracle常用SQL及重點功能說明OracleSQL
- SQL改寫的方法,select group by sumSQL
- 【AUDIT]Oracle審計配置及常用sqlOracleSQL
- 【PDB】Oracle pdb維護常用sql命令OracleSQL
- 常用SQL語句1-增刪改查SQL
- MySQL 常用 SQL 增刪改查操作詳解MySql
- 一種提升SQL改寫效率的方法SQL
- SQL 改寫系列七:謂詞移動SQL
- SQL 改寫系列六:謂詞推導SQL
- oracle_ray.sh 常用的oracle sql功能指令碼OracleSQL指令碼
- 【Oracle】常用工具-oracle sql developer快速安裝使用教程OracleSQLDeveloper
- MySQL效能優化之簡單sql改寫MySql優化
- 工作中常用的oracle資料庫sqlOracle資料庫SQL
- Oracle常用抓取SQL-標量子查詢等OracleSQL
- SQL KEEP 視窗函式等價改寫案例SQL函式
- SQL稽核 | 這裡有 MySQL/Oracle 最常用的 SQL 開發規則MySqlOracle
- SQL 抽象語法樹及改寫場景應用SQL抽象語法樹
- SQL抽象語法樹及改寫場景應用SQL抽象語法樹
- SQL 改寫系列十:半連線轉內連線SQL
- 異構資料庫遷移 sql等價改寫資料庫SQL
- oracle常用後臺程序及sql語句執行流程OracleSQL
- Oracle DB 相關常用sql彙總7【手工繫結sql執行計劃】OracleSQL
- sql改寫優化:簡單規則重組實現SQL優化
- ORACLE DBA必須記住的常用SQL命令和檢視OracleSQL
- Oracle DB 相關常用sql彙總6[知乎系列續]OracleSQL
- 【MEMORY】Oracle記憶體結構資源常用檢視及sqlOracle記憶體SQL
- 常用的sqlSQL
- 常用sql 操作SQL
- mysql 常用sqlMySql