數據表數據量接近4000萬,表中只有主鍵索引無其餘索引,建立物化視圖進行預查詢過濾sql
--每次查詢每每只須要4000萬條中的幾百條數據,所以先建立物化視圖過濾並獲得一個幾千到幾萬條數據的結果,並 建立監聽動態更新。ui
drop materialized view log on fs_budgetpayout_detail ; --不是view名,是表名 create materialized view mv_fs_budgetpayout_detail --建立物化視圖 mv_fs_budgetpayout_detail build immediate refresh fast on commit enable query rewrite as select t.fiscal, t.co_code, t.project_code, t.outlay_code , sum(t.payout_amt) payout_amt from fs_budgetpayout_detail t where t.period != 0 and t.period != 13 group by t.fiscal, t.co_code, t.project_code,t.outlay_code create materialized view log on fs_budgetpayout_detail with rowid,sequence(payout_amt,fiscal,co_code,project_code,period,outlay_code) including new values;