高效查询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

相关文章
相关标签/搜索