高效查詢SQL01

當數據庫表數據很大時,查詢的效率很低。對好比下兩個查詢:sql

select a.fund_account, count(*)
  from hs_user.fucustomzip a, hs_user.fuzipfare b
 where instr(','||a.futu_seqnos||',', ','||b.seqno||',') > 0
group by a.fund_account
order by fund_account;

在PLSQL中執行計劃以下:數據庫

在SQLPLUS統計信息以下:code

統計信息
----------------------------------------------------------
        471  recursive calls
          0  db block gets
      35724  consistent gets
          0  physical reads
          0  redo size
       6099  bytes sent via SQL*Net to client
        586  bytes received via SQL*Net from client
         21  SQL*Net roundtrips to/from client
         11  sorts (memory)
          0  sorts (disk)
        287  rows processed

能夠看到287條記錄,用了471次遞歸。遞歸

實現相同的效果:ip

select a.fund_account, (select count(*) from hs_user.fuzipfare b
where instr(','||a.futu_seqnos||',', ','||b.seqno||',') > 0) as row_num
  from hs_user.fucustomzip a
order by fund_account;

在PLSQL中的執行計劃以下:get

在SQLPLUS中統計信息以下:class

統計信息
----------------------------------------------------------
          1  recursive calls
          0  db block gets
       1437  consistent gets
          0  physical reads
          0  redo size
       7605  bytes sent via SQL*Net to client
        652  bytes received via SQL*Net from client
         27  SQL*Net roundtrips to/from client
          1  sorts (memory)
          0  sorts (disk)
        387  rows processed

統計387條記錄,只用了1次遞歸。效率

 

後續查看SQL執行效率,能夠從執行計劃和SQLPLUS中統計信息進行查看。cli

相關文章
相關標籤/搜索