SQL-Indexing-Page11
👉Indexing
Indexing a table is a way to sort and search records in the table.
Indexes are essential to improve the speed with which records can be located and retrieved from a table.
Indexing involves forming a two-dimensional matrix completely independent of the table on which the index is being created.
It consists of a column that will hold sorted data, extracted from the table column(s) on which the index is created.
Another column called the address field identifies the location of the record in the database.
When a Select is fired to search for a particular record, the database engine must first locate the table on the hard disk.
The database engine reads system information and finds the start location of a table.
Then it performs a sequential search to locate records that match user-defined criteria as specified in the "Select".
Since the data in the index is sorted, the sequential search ends as soon as the database engine reads an index data value that meets the search criteria.
Thus database engine need not search the entire indexed column.
This sharply reduces data retrieval time.
Once the data value in an index is located, the address field in an index specifies a ROWID which points to a data file, block, and the record number directly.
Thus the time taken by the database engine to locate table data on the hard disk is reduced and data retrieval time is vastly improved.
✅RowID: The address field of an index is called RowID.
RowID is an internally generated and maintained value, which uniquely identifies a record. The information in the RowID column provides the database engine the location of the table and a specific record in the database.
When the user defines a primary key or a unique key constraint, the database engine automatically creates a unique index on the primary key or unique key columns.
Note: I shall upload a detailed explanation and inner mechanism of indexing in my upcoming posts on Advanced SQL.
Comments
Post a Comment