• IOT表


        以前在接触索引的时候,就想过要是表字段太少,索引效果不是很不好吗,直接用索引不是更直接吗?后来因为懒惰也没有去查找相关资料。正好今天看到了table organization index,看了一下,实现的功能就是这个意思,这里分享给大家。

        其实正常项目中,90%以上都是正常的heap表。但我们也不能忽略那些用的少,但给我们性能带来巨大优化的其他表类型。

    首先,创建两张表:

    create table tindex
    (myid number primary key,
    myname varchar2(20))
    organization index;

    create table tindex1
    (myid number primary key,
    myname varchar2(20)) ;

    分别插入数据

    insert into tindex values(111,'abcd');
    insert into tindex1 values(111,'abcd');

    1、我们来看没有where解释计划:

    select * from tindex;

    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)|Time |

    ------------------------------------------------------------------------------------------

    | 0 | SELECT STATEMENT | | 1 | 25 | 2 (0)|00:00:01 |

    | 1 | INDEX FAST FULL SCAN| SYS_IOT_TOP_92809 | 1 | 25 | 2 (0)|00:00:01 |

    ------------------------------------------------------------------------------------------

    Note
    ------ dynamic sampling used for this statement (level=2)

    统计信息
    ----------------------------------------------------------
    0 recursive calls
    0 db block gets
    4 consistent gets
    0 physical reads
    0 redo size
    491 bytes sent via SQL*Net to client
    420 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed

    select * from tindex1;

    -----------------------------------------------------------------------------
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    -----------------------------------------------------------------------------
    | 0 | SELECT STATEMENT | | 1 | 25 | 3 (0)| 00:00:01 |
    | 1 | TABLE ACCESS FULL| TINDEX1 | 1 | 25 | 3 (0)| 00:00:01 |
    -----------------------------------------------------------------------------

    Note
    ------ dynamic sampling used for this statement (level=2)

    统计信息
    ----------------------------------------------------------
    0 recursive calls
    0 db block gets
    7 consistent gets
    0 physical reads
    0 redo size
    495 bytes sent via SQL*Net to client
    419 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed

    可以看到consistent gets相差2,通过解释计划,一个为INDEX FAST FULL SCAN,另一个是INDEX FAST FULL SCAN,相信我们也可以看出其中的原因。因为一个是按照物理顺序来读取。

    2、在我们加上条件where后,效果更加明显:

    select * from tindex where myid=111;

    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Tim

    e |

    ---------------------------------------------------------------------------------------

    | 0 | SELECT STATEMENT | | 1 | 25 | 1 (0)| 00:

    00:01 |

    |* 1 | INDEX UNIQUE SCAN| SYS_IOT_TOP_92809 | 1 | 25 | 1 (0)| 00:

    00:01 |

    select * from tindex1 where myid=111;

    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)

    | Time |

    --------------------------------------------------------------------------------

    ------------

    | 0 | SELECT STATEMENT | | 1 | 25 | 1 (0)

    | 00:00:01 |

    | 1 | TABLE ACCESS BY INDEX ROWID| TINDEX1 | 1 | 25 | 1 (0)

    | 00:00:01 |

    |* 2 | INDEX UNIQUE SCAN | SYS_C0015919 | 1 | | 1 (0)

    | 00:00:01 |

    其中一个consistent gets为1,另一个为2,原因从解释计划的执行方式可以看出,一个需要返回给heap表,另一个则不需要。

  • 相关阅读:
    Luogu 1080 【NOIP2012】国王游戏 (贪心,高精度)
    Luogu 1314 【NOIP2011】聪明的质检员 (二分)
    Luogu 1315 【NOIP2011】观光公交 (贪心)
    Luogu 1312 【NOIP2011】玛雅游戏 (搜索)
    Luogu 1525 【NOIP2010】关押罪犯 (贪心,并查集)
    Luogu 1514 引水入城 (搜索,动态规划)
    UVA 1394 And Then There Was One / Gym 101415A And Then There Was One / UVAlive 3882 And Then There Was One / POJ 3517 And Then There Was One / Aizu 1275 And Then There Was One (动态规划,思维题)
    Luogu 1437 [HNOI2004]敲砖块 (动态规划)
    Luogu 1941 【NOIP2014】飞扬的小鸟 (动态规划)
    HDU 1176 免费馅饼 (动态规划)
  • 原文地址:https://www.cnblogs.com/leafcb/p/3713353.html
Copyright © 2020-2023  润新知