Beruflich Dokumente
Kultur Dokumente
An index is a schema object that has the role to provide direct and fast
access without reading the entire table. Indexes are created explicitly or
automatically.
Create indexes after inserting table data and index on the correct
tables / columns, that are most used in queries.
Order index columns for performance and limit the number of indexes
for each table.
Assign index size and set storage parameters.
Indexes are created in the default tablespace of the schema, you can
specify the tablespace for each index.
Drop indexes that are no longer useful or no longer needed.
B-tree indexes
ON TABLE_NAME(column_name);
Bitmap indexes
ON TABLE_NAME(column_name)
TABLESPACE tbs_1
PARTITION ix_p2,
Partitioned indexes
Partitioned indexes are partitions that store an entry for each value that
appears in the indexed column of the table.
Function-based indexes are based on expressions. You can build queries that
evaluate the value returned by an expression.
ON TABLE_NAME(UPPER(column_name));
Domain indexes
You can learn how create indexes like: B-tree, bitmap, cluster index, explicit
index, unique index, function-based, index with collect statistics.
B-tree index
Compressing an Index
Create Index in NOLOGGING Mode
Create Cluster Index
Create Function-Based Index
Create Composite Index
Create Range-Partitioned Global Index
Create Hash-Partitioned Global Index
Create Index on a Hash-Partitioned Table
Create Bitmap Index
Explicit Index
Unique Explicit Index
Index Associated with a Constraint
Index with Collect Statistics
Create Index Online
B-tree index example
ON STUDENTS_LIST (student_id);
Outpout:
Check index:
FROM USER_INDEXES
WHERE TABLE_NAME='STUDENTS_LIST';
Outpout:
ORDER_DATE DATE,
);
CREATE INDEX student_orders_idx
COMPRESS 1;
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='ORDERS';
Outpout:
ORDER_DATE DATE,
ON orders (student_id)
NOLOGGING;
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='ORDERS';
Outpout:
ORDERS_IDX_NOLOGGING NORMAL NO
(course NUMBER(9))
SIZE 512
ON CLUSTER course_cluster;
Outpout:
Check cluster:
FROM USER_CLUSTERS;
Outpout:
Check index:
Outpout:
ON STUDENTS (UPPER(CITY));
ON COURSE(PRICE - DISCOUNT);
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE INDEX_NAME IN
Outpout:
Outpout:
Check indexes:
SELECT INDEX_NAME, INDEX_TYPE, UNIQUENESS
FROM USER_INDEXES
WHERE TABLE_NAME='ORDERS';
Outpout:
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='ORDERS';
Outpout:
INDEX_NAME INDEX_TYPE PARTITIONED
PK_ORDER_ID NORMAL NO
ORDERS_UNIQUE_INDEX NORMAL NO
PARTITIONS 2;
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='STUDENTS_LIST';
Outpout:
STUDENT_IDX NORMAL NO
course_name VARCHAR2(250))
PARTITIONS 2
ON test_course(course_name) LOCAL
Outpout:
Check indexes:
WHERE TABLE_NAME='TEST_COURSE';
Outpout:
SYS_C009931 NORMAL NO
course_name VARCHAR2(250),
price NUMBER
PARTITIONS 3
ON test_course(price)
PARTITION ix_p2,
TABLESPACE tbs_03;
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='TEST_COURSE';
Outpout:
SYS_C009932 NORMAL NO
Create Explicit Index example
ON STUDENTS_LIST(LAST_NAME)
TABLESPACE SYSTEM
NEXT 10k
PCTINCREASE 75);
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='STUDENTS_LIST';
Outpout:
ON PHONE_BRANDS(NAME)
TABLESPACE SYSTEM
NEXT 10k
PCTINCREASE 75);
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='PHONE_BRANDS';
Outpout:
c2 NUMBER);
Outpout:
Check indexes:
FROM USER_INDEXES
ON STUDENTS_LIST(LAST_NAME)
COMPUTE STATISTICS;
Outpout:
Check index:
FROM USER_INDEXES
WHERE TABLE_NAME='STUDENTS_LIST';
Outpout:
ONLINE;
Outpout:
Check index:
FROM USER_INDEXES
WHERE TABLE_NAME='STUDENTS_LIST';
Outpout:
You can learn how to alter indexes using commands like: rename an index,
disable an index, drop index partition, rebuild index, collect statistics.
Rename an Index
Disable an Index
Enable an Index
Disable an Function-Based Index
Enable an Function-Based Index
Rename an Index Partition
Drop an Index Partition
Disable an Index Partition
Enable an Index Partition
Collect Index Statistics
Set an Index Parallel
Rebuild an Index Partition
RENAME TO STUDENT_IDX_2;
Outpout:
Check index:
FROM USER_INDEXES
WHERE TABLE_NAME='STUDENTS_LIST';
Outpout:
To disable an oracle database index you must use the command alter index
with unusable keyword. The status of index will change FROM valid to
unusable.
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='STUDENTS_LIST';
Outpout:
In Oracle database to enable an index you must use the command alter index
with rebuild keyword. The status of index will change FROM unusable to
valid.
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='STUDENTS_LIST';
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='STUDENTS';
Outpout:
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='STUDENTS';
Outpout:
In oracle database to rename an index partition you must use the command
alter index with RENAME PARTITION keyword.
Outpout:
Check partitions:
FROM USER_IND_PARTITIONS
WHERE INDEX_NAME='AMOUNT_IDX';
Outpout:
AMOUNT_IDX P1 1
AMOUNT_IDX PART_2 2
AMOUNT_IDX PART_3 3
In oracle database to drop an index partition you must use the command alter
index with DROP PARTITION keyword.
Outpout:
Check partitions:
FROM USER_IND_PARTITIONS
WHERE INDEX_NAME='AMOUNT_IDX';
Outpout:
AMOUNT_IDX PART_1 1
AMOUNT_IDX PART_3 2
In oracle database to disable an index partition you must use the command
alter index with UNUSABLE keyword.
Outpout:
Check partitions:
FROM USER_IND_PARTITIONS
WHERE INDEX_NAME='AMOUNT_IDX';
Outpout:
In oracle database to enable an index partition you must use the command
alter index with REBUILD PARTITION keyword.
Outpout:
Check partitions:
FROM USER_IND_PARTITIONS
WHERE INDEX_NAME='AMOUNT_IDX';
Outpout:
In Oracle database to collect an index statistics you must use the command
alter index with REBUILD COMPUTE STATISTICS keyword.
Outpout:
In Oracle database to set an index parallel you must use the command alter
index with REBUILD PARALLEL keyword.
REBUILD
PARALLEL;
Outpout:
Check indexes:
FROM USER_INDEXES
WHERE TABLE_NAME='STUDENTS_LIST';
Outpout:
STUDENT_IDX 1 1
In oracle database to rebuild an index partition you must use the command
alter index with REBUILD PARTITION keyword.
Outpout:
Check partitions:
WHERE INDEX_NAME='AMOUNT_IDX';
Outpout:
AMOUNT_IDX PART_1 NO
Syntax:
Example:
Outpout:
Resources:
http://docs.oracle.com/cloud/latest/db121/SQLRF/statements_5013.htm#SQLRF012
09
http://www.plsql.co/
http://www.plsql.co/indexes.html