zoukankan      html  css  js  c++  java
  • 组合索引

    组合索引,顾名思义是多个列组成的索引。它通常会比单列的索引更有效率。

    要让oracle能够使用到一个组合索引,要求where条件中要包含该索引的先导列。比如:

    create index ind1 on test(col1,col2,col3,col4);

    对于这个组合索引,只要where条件里有col1,那么就可以使用。

    有时候,where条件不包含先导列,也仍然可以使用组合索引。这种情况叫做索引跳跃扫描 index skip scan。 不过这种情况只有是先导列唯一值比较少才有意义。因为这种模式是对先导列的所有唯一值都执行查询。

    SQL> create table test as select * from dba_objects;
    
    Table created.
    
    SQL> create index test_ont on test(owner,object_name,object_type);
    
    Index created.
    
    SQL> exec dbms_stats.gather_table_stats('SYS','TEST',cascade=>true);
    
    PL/SQL procedure successfully completed.
    
    SQL> select owner,object_name,object_type from test where object_name='TEST';
    
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 3426820653
    
    -----------------------------------------------------------------------------
    | Id  | Operation        | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    -----------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |          |     2 |    80 |    22   (0)| 00:00:01 |
    |*  1 |  INDEX SKIP SCAN | TEST_ONT |     2 |    80 |    22   (0)| 00:00:01 |
    -----------------------------------------------------------------------------
  • 相关阅读:
    重塑矩阵
    买卖股票
    两个数组的交集
    洛谷 P3700
    HDU 6987
    Solution -「NOI 2021」「洛谷 P7740」机器人游戏
    「NOI 2021」酱油记
    Solution -「UNR #5」「UOJ #671」诡异操作
    CD from Codeforces Round #703 (Div. 2)
    CD from Codeforces Round #701 (Div. 2)
  • 原文地址:https://www.cnblogs.com/kramer/p/3899723.html
Copyright © 2011-2022 走看看