zoukankan      html  css  js  c++  java
  • [ORALCE]SQL 优化案例之 组合索引的前缀和单列索引一致

    • 组合索引的前缀和单列索引一致,走INDEX RANGE SCAN
    drop table TX1 purge;
    create table TX1 as select * from dba_objects;
    SQL> select count(*) from (select distinct object_id from TX1);
    
      COUNT(*)
    ----------
         73396
    SQL> select count(*) from (select distinct object_type from TX1);
    
      COUNT(*)
    ----------
        47
    create index idx_object_id on TX1(object_id,object_type);
    set autotrace on
    set linesize 150
    
    select * from TX1 where object_id=19;
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1750502627
    
    -----------------------------------------------------------------------------------------------------
    | Id  | Operation                | Name        | Rows  | Bytes | Cost (%CPU)| Time     |
    -----------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT            |            |      1 |    481 |      3   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID BATCHED| TX1        |      1 |    481 |      3   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN            | IDX_OBJECT_ID |      1 |        |      2   (0)| 00:00:01 |
    -----------------------------------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       2 - access("OBJECT_ID"=19)
    
    Note
    -----
       - dynamic statistics used: dynamic sampling (level=2)
    
    
    Statistics
    ----------------------------------------------------------
         34  recursive calls
          0  db block gets
        164  consistent gets
          1  physical reads
          0  redo size
           2686  bytes sent via SQL*Net to client
        398  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed
    • 组合索引的前缀和单列索引不一致,走FULL TABLE SCAN
    drop index idx_object_id;
    create index idx_object_id on TX1(object_type,object_id);
    select * from TX1 where object_id=19;
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 2923622636
    
    --------------------------------------------------------------------------
    | Id  | Operation      | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------
    |   0 | SELECT STATEMENT  |     |    16 |  7696 |   459   (1)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL| TX1  |    16 |  7696 |   459   (1)| 00:00:01 |
    --------------------------------------------------------------------------
    
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       1 - filter("OBJECT_ID"=19)
    
    Note
    -----
       - dynamic statistics used: dynamic sampling (level=2)
    
    
    Statistics
    ----------------------------------------------------------
          5  recursive calls
          0  db block gets
           1514  consistent gets
          0  physical reads
          0  redo size
           2686  bytes sent via SQL*Net to client
        398  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed
  • 相关阅读:
    项目团队技术个人(提拔篇)
    Android开发者掘金(2)—技术篇
    Android开发者掘金(3) 未来
    在Android应用中放置AdMob广告的详细教程
    ant build apk
    手机产品设计中的 15 大禁忌
    Android开发者掘金(1)
    项目团队技术个人(专业篇)
    #pragram预处理指令
    c++ 异常机制
  • 原文地址:https://www.cnblogs.com/tingxin/p/12846767.html
Copyright © 2011-2022 走看看