VISIBLE AND INVISIBLE options for indexes
Visibility option for indexes decides availability of the index to the optimizer during query optimization.
- VISIBLE
- An index that is set to be visible. A visible index is maintained and may be considered but not necessarily used by the optimizer. VISIBLE keyword is optional.
- INVISIBLE
- An index that is set to be invisible, is maintained but ignored by the optimizer.
The indexes are considered by the optimizer unless the indexes are disabled or directives are used. When the index is disabled, it is not maintained. Enabling a disabled index rebuilds the index.
A newly created index will be visible by default or can be set to visible using VISIBLE keyword while creating it. Use the INVISIBLE keyword of the CREATE INDEX statement to create an invisible index. The index will be created as invisible or can be made invisible from being visible.
CREATE TABLE tab1(col1 int, col2 int, col3 int);
CREATE INDEX idx1 on tab1(col1);
CREATE INDEX idx2 on tab1(col2) VISIBLE;
CREATE INDEX idx3 on tab1(col3) INVISIBLE;
idx1 and idx2 will be created VISIBLE. Although idx1 is created without the VISIBLE keyword, by default it is VISIBLE. idx3 will be created INVISIBLE.
Dbschema/Dbexport and VISIBLE/INVISIBLE indexes
If the index is created invisible or made invisible using the SET INDEXES statement, dbschema and dbexport will append invisible keyword to the create index statement.
Using the indexes created in Example 1, dbschema output will be:
After the create index statements:
create index "uaymak1".idx1 on "uaymak1".tab1 (col1) using btree ;
create index "uaymak1".idx2 on "uaymak1".tab1 (col2) using btree ;
create index "uaymak1".idx3 on "uaymak1".tab1 (col3) using btree invisible ;
Indexes are set from visible to invisible and vice versa:
set indexes "uaymak1".idx1 INVISIBLE ;
set indexes "uaymak1".idx2 INVISIBLE ;
set indexes "uaymak1".idx3 VISIBLE ;
After the set indexes statements:
create index "uaymak1".idx1 on "uaymak1".tab1 (col1) using btree invisible ;
create index "uaymak1".idx2 on "uaymak1".tab1 (col2) using btree invisible ;
create index "uaymak1".idx3 on "uaymak1".tab1 (col3) using btree ;