Rebuilding index
In the previous recipe, we saw that using indexes leads to performance improvements; however, we need to take care that DML operations are slower due to the operations involved to keep the index synchronized with table data.
Rebuilding an index is an operation that can provide performance benefits because it reduces intra-block fragmentation.
Getting ready
The following steps have to be carried out initially:
Open a SQL*Plus session and connect to the SH schema:
CONNECT sh@TESTDB/sh
Create a table to test:
CREATE TABLE BIG_CUSTOMERS AS SELECT * FROM CUSTOMERS;
Insert more than 5 million records:
BEGIN FOR j IN 1..100 LOOP INSERT INTO BIG_CUSTOMERS SELECT * FROM CUSTOMERS; END LOOP; COMMIT; END;
Instruct SQL*Plus to show the timings for the next operations:
SET TIMING ON
Create an index on the table:
CREATE INDEX IX1_BIG_CUSTOMERS ON BIG_CUSTOMERS (CUST_LAST_NAME, CUST_FIRST_NAME);
How to do it...
In this recipe, we will see how to rebuild an index minimizing the effects...