1. 程式人生 > >Union 和 Union all + distinct 效能比較

Union 和 Union all + distinct 效能比較


 測試資料量查詢結果資料量是1百多萬
 測試環境oracle11g 單例項環境

 結論:在大資料量的情況下distinct + union all  效能大於 UNION 的效能

1.distinct + union all 場景

 ---資料量1074177--  ----用時2.158秒----
 SELECT COUNT(*) FROM (
 SELECT DISTINCT * FROM (
SELECT  trim(ACNO) as ACNO,DAT,LOGACNO,SENO,PROVICEID  FROM TABLE_R  UNION ALL
SELECT  trim(ACNO) as ACNO,DAT,LOGACNO,SENO,PROVICEID FROM TABLE_BAL UNION ALL 

SELECT  trim(ORI_ACNO) as ACNO,ORI_DAT,ORI_LOGACNO,ORI_SENO,PROVICEID FROM TABLE_BAL ));

2.union場景 

---資料量1074177--  ----用時5.369秒----

SELECT COUNT(*) FROM (
SELECT  trim(ACNO) as ACNO,DAT,LOGACNO,SENO,PROVICEID  FROM TABLE_R  UNION
SELECT  trim(ACNO) as ACNO,DAT,LOGACNO,SENO,PROVICEID FROM TABLE_BAL UNION
SELECT  trim(ORI_ACNO) as ACNO,ORI_DAT,ORI_LOGACNO,ORI_SENO,PROVICEID FROM TABLE_BAL );