简体   繁体   中英

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 ) ?

Thanks.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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