Oracle equivalent to SQL Server included columns to index

[亡魂溺海] 提交于 2021-02-07 06:16:27

问题


Does Oracle let me include columns to index (like SQL Server INCLUDE clause in CREATE INDEX) ?

Thanks.


回答1:


No. An index in Oracle either includes the column in the index itself or it doesn't.

Depending on the problem you are trying to solve, however, an index-organized table may be the appropriate analogue in Oracle.




回答2:


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.



来源:https://stackoverflow.com/questions/7125577/oracle-equivalent-to-sql-server-included-columns-to-index

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!