Oracle 中的 INCLUDE 等效项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5108651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 22:52:04  来源:igfitidea点击:

INCLUDE equivalent in Oracle

sql-serveroracleindexing

提问by Michael

In SQL server you can write

在 SQL 服务器中,您可以编写

create index indx on T1 (A,B) INCLUDE (C,D,E) 

Is there a way to do the same thing in Oracle?

有没有办法在 Oracle 中做同样的事情?

采纳答案by redcayuga

Simply put all the columns in the index:

只需将所有列放在索引中:

create index indx on T1 (A,B,C,D,E)

create index indx on T1 (A,B,C,D,E)

If Oracle decides to use your index (e.g., A and B are in the WHERE clause) it will take the values of C, D, and E from the index.

如果 Oracle 决定使用您的索引(例如,A 和 B 在 WHERE 子句中),它将从索引中获取 C、D 和 E 的值。

If the columns are very long varchars Oracle may not be able to build the index. This is sometimes called a "covered" index and I've used or seen it on more than a few occasions.

如果列很长 varchars Oracle 可能无法建立索引。这有时被称为“覆盖”索引,我已经多次使用或看到它。

回答by RichardTheKiwi

Refs:
http://msdn.microsoft.com/en-us/library/ms190806.aspx
http://www.dba-oracle.com/t_garmany_easysql_btree_index.htm

参考:
http: //msdn.microsoft.com/en-us/library/ms190806.aspx
http://www.dba-oracle.com/t_garmany_easysql_btree_index.htm

This answer is here to point out that SQL Server Included columns do not store the INCLUDED columns at the key levels, only at the leaf level. If you include 4 columns, they get stored as data in a block on the leaf level.

这个答案在这里指出 SQL Server Included 列不在键级别存储 INCLUDED 列,仅在叶级别存储。如果包含 4 列,它们将作为数据存储在叶级别的块中。

Creating them as additional parts of a composite index breaks the index into more levels instead.

将它们创建为复合索引的附加部分,而是将索引分解为更多级别。

As composite index (A,B,C)

作为综合指数 (A,B,C)

  Level1   Level2   Leaf
           (Branch)
  A1
           B1
                    C1
           B2
                    C3
           B3
                    C6
                    C7
  A2

As index (A) include (B,C)

由于索引 (A) 包括 (B,C)

  Level1    Leaf
  A1        B1,C1 | B2,C3 | B3,C6 | B3,C7
  A2        null,null

The difference in storage structure (which affects performance) is the reason why they are introduced as INCLUDED columns, otherwise there would be no reason to introduce this new feature.

存储结构的差异(影响性能)是将它们作为 INCLUDED 列引入的原因,否则就没有理由引入这个新功能。

回答by Jon Heller

You can create an index organized table and only store specific columns with the key. Note that you don't list the columns to include, you only list the last one and it includes all the columns up to that. (Which seems odd, usually column order doesn't matter in SQL.) Personally, I think index organized tables are weird and have too many limitations, redcayuga's idea is probably better.

您可以创建一个索引组织的表,并且只存储带有键的特定列。请注意,您没有列出要包含的列,您只列出了最后一列,并且包含了到此为止的所有列。(这看起来很奇怪,通常列顺序在 SQL 中并不重要。)就个人而言,我认为索引组织的表很奇怪并且有太多限制,redcayuga 的想法可能更好。

create table t1
(
    a number,
    b number,
    c number,
    d number,
    e number,
    f number,
    g number,
    primary key (a, b, c)
)
organization index
including e
overflow;