Creating a proper index can accelerate the retrieval of data rows in a table. Indexes occupy disk space and reduce the speed of adding, deleting, and updating rows. If data needs to be updated very frequently or disk space is limited, you need to limit the number of indexes. Create indexes for large tables. Because the more data in the table, the more effective the index is. You are advised to create indexes on:
The column-store partitioned table orders is defined as follows:
Run the SQL statement to query the execution plan when no index is created. It is found that the execution time is 48 milliseconds.
1 | EXPLAIN PERFORMANCE SELECT * FROM orders WHERE o_custkey = '1106459'; |
The filtering condition column of the where clause is o_custkey. Add an index to the o_custkey column.
1 | CREATE INDEX idx_o_custkey ON orders (o_custkey) LOCAL; |
Run the SQL statement to query the execution plan after the index is created. It is found that the execution time is 18 milliseconds.