2015-08-20 75 views
-2

我用多個視圖來使用子查詢和聯合來獲取兩列,我想減少這個執行時間。選擇兩列:多視圖,相同的條件

select a.empid,empname from 
(select empid,empname from india_emp where deptno <> 10 
union 
select empid,empname from us_emp where deptno <> 10 
union 
select empid,empname from uk_emp where deptno <> 10 
union 
select empid,empname from uae_emp where deptno <> 10 
union 
select empid,empname from brazl_emp where deptno <> 10 
union 
select empid,empname from chine_emp where deptno <> 10 
union 
select empid,empname from jpn_emp where deptno in (54,256,362,9879,24,46) 
)a 
where a.empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446) 
order by 2 
+2

張貼執行計劃 – Matt

+2

有沒有什麼可以繼續下去。針對同一個基表的觀點是什麼?是否有任何單個查詢比其他查詢慢?執行計劃是否顯示出瓶頸?它是否使用了適當的索引?統計信息是否最新?等等......縮短執行時間也是一個非常模糊的目標。 –

+0

我是新的Oracle DBA,這是我的第一個SQL查詢優化,我看到執行計劃,但我不明白真的很好,我只理解這個上面的查詢使用全掃描表,我已經創建索引在主表,然後創建不同的許多之後的意見,我選擇他的數據,但其執行時間是04.52秒和225條記錄,我想減少這個執行時間,但不知道如何?所以如果你能告訴我如何減少?給我的方式或任何建議..預先感謝提供快速響應... –

回答

0

更改所有UnionUnion All,這是更便宜。

像這樣:具有派生表內EMPID過濾

SELECT a.empid,empname FROM 
(SELECT empid,empname FROM india_emp WHERE deptno <> 10 
UNION ALL 
SELECT empid,empname FROM us_emp WHERE deptno <> 10 
UNION ALL 
SELECT empid,empname FROM uk_emp WHERE deptno <> 10 
UNION ALL 
SELECT empid,empname FROM uae_emp WHERE deptno <> 10 
UNION ALL 
SELECT empid,empname FROM brazl_emp WHERE deptno <> 10 
UNION ALL 
SELECT empid,empname FROM chine_emp WHERE deptno <> 10 
UNION ALL 
SELECT empid,empname FROM jpn_emp WHERE deptno in (54,256,362,9879,24,46) 
)a 
WHERE a.empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446) 
ORDER BY 2 
+0

我已經把聯盟所有,但不是好的作品,它只有10毫秒減少 –

0

可以嘗試瘦身?

select a.empid,empname from 
(select empid,empname from india_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446) 
union 
select empid,empname from us_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446) 
union 
select empid,empname from uk_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446) 
union 
select empid,empname from uae_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446) 
union 
select empid,empname from brazl_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446) 
union 
select empid,empname from chine_emp where deptno <> 10 and empid NOT IN(105,202,11,45,695,646,726,8465,965,56,646,689,446) 
union 
select empid,empname from jpn_emp where deptno in (54,256,362,9879,24,46) 
)a 
where 
order by 2 
+0

如果Oracle認爲它會幫助自動推斷謂詞。 –

+0

我使用但不工作,我曾經喜歡你說寫上面的類型查詢寫它的增加執行時間..謝謝你的建議,但沒有工作.. –