简体   繁体   English

oracle- index组织表

[英]oracle- index organized table

what is use-case of IOT ( Index Organized Table ) ? IOT( Index Organized Table )的用例是什么?

Let say I have table like 假设我有桌子

  1. id ID
  2. Name 名称
  3. surname

i know the IOT but bit confuse about the use case of IOT 我知道IOT但有点混淆有关的使用情况IOT

Your three columns don't make a good use case. 你的三个专栏没有成为一个好的用例。

IOT are most useful when you often access many consecutive rows from a table. 当您经常从表中访问许多连续行时,IOT最有用。 Then you define a primary key such that the required order is represented. 然后定义主键,以便表示所需的顺序。

A good example could be time series data such as historical stock prices. 一个很好的例子可能是时间序列数据,如历史股票价格。 In order to draw a chart of the stock price of a share, many rows are read with consecutive dates. 为了绘制股票股票价格的图表,读取连续日期的许多行。

So the primary key would be stock ticker (or security ID) and the date. 所以主键是股票代码(或安全ID)和日期。 The additional columns could be the last price and the volume. 附加列可以是最后的价格和数量。

A regular table - even with an index on ticker and date - would be much slower because the actual rows would be distributed over the whole disk. 常规表 - 即使是自动收报机和日期的索引 - 也会慢得多,因为实际的行将分布在整个磁盘上。 This is because you cannot influence the order of the rows and because data is inserted day by day (and not ticker by ticker). 这是因为您不能影响行的顺序,因为数据是每天插入的(而不是自动收报机)。

In an index-organized table, the data for the same ticker ends up on a few disk pages, and the required disk pages can be easily found. 在索引组织表中,同一个自动收报机的数据最终会出现在几个磁盘页面上,并且可以轻松找到所需的磁盘页面。

Setup of the table: 表的设置:

CREATE TABLE MARKET_DATA
  (
    TICKER VARCHAR2(20 BYTE) NOT NULL ENABLE,
    P_DATE DATE NOT NULL ENABLE,
    LAST_PRICE NUMBER,
    VOLUME     NUMBER,
    CONSTRAINT MARKET_DATA_PK PRIMARY KEY (TICKER, P_DATE) ENABLE
  )
  ORGANIZATION INDEX;

Typical query: 典型查询:

 SELECT TICKER, P_DATE, LAST_PRICE, VOLUME
 FROM MARKET_DATA
 WHERE TICKER = 'MSFT'
 AND P_DATE BETWEEN SYSDATE - 1825 AND SYSDATE
 ORDER BY P_DATE;

Think of index organized tables as indexes. 将索引组织表视为索引。 We all know the point of an index: to improve access speeds to particular rows of data. 我们都知道索引的要点:提高对特定数据行的访问速度。 This is a performance optimisation of trick of building compound indexes on sub-sets of columns which can be used to satisfy commonly-run queries. 这是在列子集上构建复合索引的技巧的性能优化,可用于满足常用查询。 If an index can completely satisy the columns in a query's projection the optimizer knows it doesn't have to read from the table at all. 如果索引可以完全满足查询投影中的列,则优化器知道它根本不必从表中读取。

IOTs are just this approach taken to its logical confusion: buidl the index and throw away the underlying table. IOT只是这种方法的逻辑混乱:buidl索引并扔掉基础表。

There are two criteria for deciding whether to implement a table as an IOT: 决定是否将表实现为IOT有两个标准:

  1. It should consists of a primary key (one or more columns) and at most one other column. 它应该包含一个主键(一个或多个列)和至多一个其他列。 (okay, perhaps two other columns at a stretch, but it's an warning flag). (好吧,也许是其他两个专栏,但它是一个警告标志)。
  2. The only access route for the table is the primary key (or its leading columns). 该表的唯一访问路径是主键(或其主要列)。

That second point is the one which catches most people out, and is the main reason why the use cases for IOT are pretty rare. 第二点是吸引大多数人的问题,也是IOT用例非常罕见的主要原因。 Oracle don't recommend building other indexes on an IOT, so that means any access which doesn't drive from the primary key will be a Full Table Scan. Oracle建议不要在IOT上构建其他索引,这意味着任何不从主键驱动的访问都将是全表扫描。 That might not matter if the table is small and we don't need to access it through some other path very often, but it's a killer for most application tables. 如果表很小并且我们不需要经常通过其他路径访问它可能无关紧要,但它对于大多数应用程序表来说都是一个杀手。

It is also likely that a candidate table will have a relatively small number of rows, and is likely to be fairly static. 候选表也可能具有相对较少的行数,并且可能是相当静态的。 But this is not a hard'n'fast rule; 但这不是一个严格的规则; certainly a huge, volatile table which matched the two criteria listed above could still be considered for implementations as an IOT. 当然,与上面列出的两个标准相匹配的巨大的,易变的表仍然可以考虑用作IOT的实现。

So what makes a good candidate dor index organization? 那么什么才能成为一个好的候选人指数组织? Reference data. 参考数据。 Most code lookup tables are like something this: 大多数代码查找表都像这样:

code number not null primary key
description not null varchar2(30)

Almost always we're only interested in getting the description for a given code. 几乎总是我们只对获取给定代码的描述感兴趣。 So building it as an IOT will save space and reduce the access time to get the description. 因此,将其构建为IOT将节省空间并减少获取描述的访问时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM