What is Database Indexing?

What is Database Indexing?

And when to use it?

1. What is a database index?

• An index is a data structure, stored alongside a table, that helps in faster access of records from a table.

• It is created against a column and stores the location of the row for that column value.

2. Why is an index required?

• An index helps in the faster access of data from the table.

• As it stores the pointer to the table, the I/O operations required are reduced drastically, resulting in higher performance.

3. What are some key features of indexes?

• It's used for read-heavy operations.

• When updating a row/column, an index associated with that needs to get updated as well, slowing the performance.

• The most popular data structures used for creating indexes are B-Trees and Hash Tables. (I won't go into specifics as these are well-known data structures)

• B-Trees are generally preferred due to their logarithmic time complexity of CRUD operations.

• Indexes are only used when querying an indexed column with a specific value. They can't be used with commands such as "like".

• An index for the primary key is created by default.

• Since indexes are stored alongside the table, they require additional storage. So, we need to create indexes carefully.

• An index for the primary key is created by default.

• Creating an index for a column that is read rarely or is updated frequently is a terrible idea.

References and further reads

stackoverflow.com/questions/1108/how-does-d..

youtube.com/watch?v=T9n_-_oLrbM&list=PL..

Did I miss anything? Add it in the comments!

Did you find this article valuable?

Support Aditya Gupta by becoming a sponsor. Any amount is appreciated!