Index in databases

Understanding Indexing in Databases
Many newcomers to the software and programming world encounter terminology and concepts that are not typically covered at the junior level. As you begin to move beyond the basics, there are certain concepts and keywords that you are expected to understand. One such concept is the Index, and today we are going to learn about indexing in databases.
In short, indexing in databases is a data structure technique used to speed up data retrieval operations by minimizing the number of disk accesses required to locate records.
Attributes of Indexing
Several important attributes of indexing affect the performance and efficiency of database operations:
- Access Types: This refers to the type of access, such as value-based search, range access, and so on.
- Access Time: Refers to the time needed to find a particular data element or set of elements.
- Insertion Time: Refers to the time taken to find the appropriate space and insert new data.
- Deletion Time: Refers to the time taken to find an item and delete it, as well as to update the index structure.
- Space Overhead: Refers to the additional storage space required to maintain the index.
File Organization in Indexing
File organization refers to how data and indexes are physically stored in memory or on disk. The following are the common types of file organizations used in indexing:
Sequential File Organization
In the sequential approach, there are two methods. The first is the dense index, in which for each index entry (such as the ID in a user table) there is one corresponding value (such as the username), and the structure is key-value based.
The second method is the sparse index. In this approach, the data is split into groups, and each group is then used as an index entry. For example, assume we have one billion users, with IDs ranging from 1 to 1,000,000,000. To manage this, we divide the range into groups: users with IDs from 1 to 250,000,000 go into one group, users with IDs from 250,000,001 to 500,000,000 go into a second group, and so on, resulting in four groups in total. When we need to find a user with a specific ID, such as 500,000,001, we first locate the relevant group and then perform a simple search within that group. This approach makes it easier to identify the correct category and group before searching for the individual record.