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
  • 相关阅读:
    hadoop项目放在tomcat服务器中遇见的问题
    hadoop-hdfs间文件复制
    fastdfs扩容
    mysql-8.0修改密码方式
    同一个服务器启动两个redis服务记录!
    springboot+vue完美跨域 解决sessionId不一致问题
    docker 拉取fastDFS镜像
    共享锁、排他锁、互斥锁、悲观锁、乐观锁、行锁、表锁、页面锁、不可重复读、丢失修改、读脏数据
    linux下后台运行node-js项目
    概念解释:分组密码、流密码、对称密码、非对称密码
  • 原文地址:https://www.cnblogs.com/tingxin/p/12846767.html
Copyright © 2011-2022 走看看