How can I make newly added indexes in Oracle take effect?
To make the newly created index take effect, you need to perform the following steps:
- To create an index: use the CREATE INDEX statement to create an index. The syntax is as follows:
CREATE INDEX index_name ON table_name (column_name);
index_name is the name of the index, table_name is the name of the table where the index will be created, and column_name is the name of the column to be indexed.
- Confirm that the index has been successfully created: You can use the following statement to check if the index has been successfully created:
SELECT index_name FROM user_indexes WHERE table_name = 'table_name';
“table_name is the name of the table to be queried.”
- Update statistical information: The performance of indexes depends on the statistical information of the table. You can update the statistical information of the table using the following statement.
BEGIN
DBMS_STATS.GATHER_TABLE_STATS('schema_name', 'table_name');
END;
In which schema_name is the name of the schema where the table is located, and table_name is the name of the table for which to update statistics.
- To force a recompilation of stored procedures and functions: If the created indexes are related to the stored procedures or functions, it may be necessary to force a recompilation of these objects in order to use the new indexes. You can use the following statement to force a recompilation of stored procedures and functions:
ALTER PROCEDURE procedure_name COMPILE;
ALTER FUNCTION function_name COMPILE;
In which, procedure_name refers to the name of the stored procedure, while function_name refers to the name of the function.
Please note that creating indexes can lead to a decrease in the performance of insertions, updates, and deletions, as the database needs to update the indexes every time table data is modified. Therefore, it is important to use indexes carefully and conduct thorough testing and evaluation before creating them.