简体   繁体   English

相当于 SQL Server 的 Oracle 包含要索引的列

[英]Oracle equivalent to SQL Server included columns to index

Does Oracle let me include columns to index (like SQL Server INCLUDE clause in CREATE INDEX ) ? Oracle 是否让我包含要索引的列(如CREATE INDEX SQL Server INCLUDE子句)?

Thanks.谢谢。

No. An index in Oracle either includes the column in the index itself or it doesn't.不可以。Oracle 中的索引要么在索引本身中包含该列,要么不包含该列。

Depending on the problem you are trying to solve, however, an index-organized table may be the appropriate analogue in Oracle.然而,根据您要解决的问题,索引组织表可能是 Oracle 中的适当类似物。

CREATE TABLE test (
    a       VARCHAR2(400 char) NOT NULL PRIMARY KEY,
    b       NUMBER(33) NOT NULL
);

CREATE TABLE test_2 (
    a       VARCHAR2(400 char) NOT NULL,
    b       NUMBER(33) NOT NULL
);
CREATE INDEX ix_test_2 ON test_2(a, b);

explain plan for
select a,b from test where a in ('a', 'b', 'c');

--|   0 | SELECT STATEMENT(50)
--|   1 |  INLIST ITERATOR
--|   2 |   TABLE ACCESS BY INDEX ROWID
--|*  3 |    INDEX UNIQUE SCAN         

explain plan for
select a,b from test_2 where a in ('a', 'b', 'c');

--|   0 | SELECT STATEMENT
--|   1 |  INLIST ITERATOR       
--|*  2 |   INDEX RANGE SCAN

So, to me it looks like that in Oracle12c at least, including column b in the index prevents table access -> faster.所以,在我看来,至少在 Oracle12c 中,在索引中包含 b 列会阻止表访问 -> 更快。

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

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