国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Oracle > 正文

關于Oracle 9i 跳躍式索引掃描(Index Skip Scan)的小測試

2024-08-29 13:31:30
字體:
來源:轉載
供稿:網友
  • 網站運營seo文章大全
  • 提供全面的站長運營經驗及seo技術!


  • 在oracle9i中我們知道能夠使用跳躍式索引掃描(index skip scan).然而,能利用跳躍式索引掃描的情況其實是有些限制的.

    從oracle的文檔中我們可以找到這樣的話:

    index skip scans
    index skip scans improve index scans by nonprefix columns.
    often, scanning index blocks is faster than scanning table data blocks.
    skip scanning lets a composite index be split logically into smaller subindexes.
    in skip scanning, the initial column of the composite index is not specified in the query.
    in other words, it is skipped.

    the number of logical subindexes is determined by the number of distinct values in the initial column.
    skip scanning is advantageous if there are few distinct values in the leading column of the composite
    index and many distinct values in the nonleading key of the index.

    也可以這樣說,優化器根據索引中的前導列(索引到的第一列)的唯一值的數量決定是否使用skip scan.

    我們首先做個測試:

    sql> create table test as
      2  select rownum a,rownum-1 b ,rownum-2 c,rownum-3 d,rownum-4 e
      3  from all_objects
      4  /

    sql> select distinct count (a) from test;

      count(a)
    ----------
         28251

    表已創建。

    sql>
    sql> create index test_idx on test(a,b,c)
      2  /

    索引已創建。

    sql> analyze table test compute statistics
      2  for table
      3  for all indexes
      4  for all indexed columns
      5  /

    表已分析。

    sql> set autotrace traceonly explain
    sql> select *  from test where b = 99
      2  /

    execution plan
    ----------------------------------------------------------
       0      select statement optimizer=choose (cost=36 card=1 bytes=26)
       1    0 table access (full) of 'test' (cost=36 card=1 bytes=26)

    --可見這里cbo選擇了全表掃描.

    --我們接著做另一個測試:

    sql> drop table test;

    表已丟棄。

    sql> create table test
      2  as
      3  select decode(mod(rownum,2), 0, '1', '2' ) a,
      4                    rownum-1 b,
      5                    rownum-2 c,
      6                    rownum-3 d,
      7                    rownum-4 e
      8    from all_objects
      9  /

    表已創建。

    sql> set autotrace off
    sql> select distinct a from test;

    a
    --
    1
    2

    --a列只有兩個唯一值

    sql> create index test_idx on test(a,b,c)
      2  /

    索引已創建。


    sql> analyze table test compute statistics
      2  for table
      3  for all indexes
      4  for all indexed columns
      5  /

    表已分析。

    sql> set autotrace traceonly explain
    sql> select *  from test where b = 99
      2  /

    execution plan
    ----------------------------------------------------------
       0      select statement optimizer=choose (cost=4 card=1 bytes=24)
       1    0   table access (by index rowid) of 'test' (cost=4 card=1 bytes=24)
       2    1     index (skip scan) of 'test_idx' (non-unique) (cost=3 card=1)

     

    oracle的優化器(這里指的是cbo)能對查詢應用index skip scans至少要有幾個條件:

    1 優化器認為是合適的.
    2 索引中的前導列的唯一值的數量能滿足一定的條件.
    3 優化器要知道前導列的值分布(通過分析/統計表得到)
    4 合適的sql語句
    ......


    更多信息請參考:

    http://www.itpub.net/showthread.php?threadid=85948

    http://www.cnoug.org/bin/ut/topic_show.cgi?id=608&h=1&bpg=1&age=100

    http://www.itpub.net/showthread.php?s=&postid=985602#post985602

    oracle9i database performance tuning guide and reference release 2 (9.2)
    part number a96533-02

    感謝參加討論的各位高手.
    發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 冷水江市| 土默特右旗| 吉水县| 浦县| 阿克| 恩施市| 镇沅| 洛阳市| 岚皋县| 淅川县| 永登县| 师宗县| 通辽市| 延寿县| 盱眙县| 临汾市| 道孚县| 荣昌县| 博客| 福泉市| 上高县| 齐齐哈尔市| 塘沽区| 石渠县| 东城区| 永安市| 桐柏县| 怀化市| 凤山市| 芷江| 赤峰市| 麻阳| 昭平县| 亳州市| 二手房| 红河县| 霍城县| 偏关县| 津市市| 浦县| 开封市|