oracle 單列索引 多列索引的效能測試

來源:互聯網
上載者:User

標籤:style   io   color   使用   sp   strong   資料   on   2014   

清除oralce 緩衝:alter system flush buffer_cache;

環境:oracle 10g 、 400萬條資料,頻率5分鐘一條

1.應用情境:  找出所有網站的最新一條資料。sql語句如下:

——————————————————————————————————————————————————

with aa as(
select t1.EQP_ID ,max(MEASURE_TIME) maxtm from PLU_WATER_DATA t1 where t1.MEASURE_TIME >= to_date(‘2014-01-28 00:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘)
and t1.MEASURE_TIME < to_date(‘2014-01-28 02:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘) group by t1.EQP_ID

)
, bb as
(
select T1.EQP_ID as STCD,
T1.MEASURE_TIME as TM,
T1.FLUX_VALUE as FLOW
from PLU_WATER_DATA T1
where t1.MEASURE_TIME >= to_date(‘2014-01-28 00:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘)
and t1.MEASURE_TIME < to_date(‘2014-01-28 02:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘)

)
select * from aa inner join bb on aa.EQP_ID = bb.stcd and aa.maxtm = bb.tm inner join vi_plustation cc on cc.stcd =aa.EQP_ID

 ——————————————————————————————————————————

執行結果:

a.建立tm+stcd多列索引、tm單列索引、stcd單列索引  (執行時間2秒)
b.建立tm+stcd多列索引、stcd單列索引 (執行時間20秒)
c.建立stcd單列索引 (執行時間N秒)
d.建立tm+stcd多列索引 (執行時間22秒)
e.建立tm+stcd+tn+tp+cod多列索引 (執行時間71秒)
f.建立tm單列索引 (執行時間2秒)

 

2.應用情境  :  找出單個網站的一段時間內的資料。sql語句如下:

select T1.EQP_ID as STCD,
T1.MEASURE_TIME as TM,
T1.FLUX_VALUE as FLOW
from PLU_WATER_DATA T1
where t1.MEASURE_TIME >= to_date(‘2014-01-28 00:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘)
and t1.MEASURE_TIME < to_date(‘2014-01-28 23:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘) and eqp_id = ‘1244‘

執行結果:

查詢條件在 tm和stcd上
a. 建立tm單列索引 (執行時間17秒)
b. 建立tm單列索引、stcd單列索引 (執行時間 3秒)
c. 建立tm單列索引、stcd單列索引、tm+stcd多列索引 (執行時間 0.5秒)
d. 建立tm+stcd多列索引 (執行時間 0.7秒)

 

3.結論:查詢條件中stcd或者tm是單獨限制where條件,如果使用了stcd+tm的多列索引,效率降低。如果stcd和tm是作為聯合where條件,建立stcd和tm的單列索引,效率明顯低於使用stcd+tm的多列索引。

  a.當一個sql語句有網站分組跟時間查詢嵌套使用時,推薦將stcd和tm分開建立單列索引。列如:

select t1.EQP_ID ,max(MEASURE_TIME) maxtm from PLU_WATER_DATA t1 where t1.MEASURE_TIME >= to_date(‘2014-01-28 00:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘) and t1.MEASURE_TIME < to_date(‘2014-01-28 02:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘) group by t1.EQP_ID)

像這樣的語句如果建立的是 stcd+tm的多列索引,那麼讀取速度是7m,而如果使用stcd和tm分開建立單列索引,速度在2m內。

  b.當一個sql語句 指定“網站”和“時間”時,推薦建立stcd+tm多列索引。例如

select T1.EQP_ID as STCD,T1.MEASURE_TIME as TM,T1.FLUX_VALUE as FLOW from PLU_WATER_DATA T1 
where t1.MEASURE_TIME >= to_date(‘2014-01-28 00:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘)
and t1.MEASURE_TIME < to_date(‘2014-01-28 23:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘) and eqp_id = ‘1244‘

像這樣的語句如果建立的是stcd和tm分開建立單列索引,速度在3m,但如果建立了stcd+tm的多列索引,速度在0.7m

 c.當一個sql語句 制定“時間”查詢時,推薦建立 tm單列索引。例如

select T1.EQP_ID as STCD,T1.MEASURE_TIME as TM,T1.FLUX_VALUE as FLOW from PLU_WATER_DATA T1 
where t1.MEASURE_TIME >= to_date(‘2014-01-28 00:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘)
and t1.MEASURE_TIME < to_date(‘2014-01-28 23:00:00‘, ‘yyyy-MM-dd hh24:mi:ss‘)

像這樣的語句如果建立的是stcd+tm的複合索引,速度在5m,如果建立在tm的單列索引上,速度在1.5m

oracle 單列索引 多列索引的效能測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.