The index is a database object that improves performance when you optimize it on the table. Here are some rules that can help you create efficient indexes. An index is used to speed up the retrieval of rows from the database table.

IN THIS PAGE

  1. What is an index
  2. Rules to create an index: When is needed
  3. When an index is not needed
DB2 indexes
Photo by Pixabay on Pexels.com

What is an index

The index is separate from the table it indexes. It contains pointers to the data in the table. The database management system (DBMS) automatically maintains the indexes and uses them to fulfill certain user queries. It is the responsibility of the software engineer or database administrator (DBA) to create indexes. Visit this link to learn how to create an index.

Rules to create an index: When is needed

  • In SQL queries, a particular column or combination of columns is used frequently.
  • The column has a wide range of values.
  • The column also contains a large number of null values.
  • The table is large, and most queries only expect a small percentage (2% – 4%) of the rows.
  • In queries, the mentioned column or combination of columns is often used in the Order-by-clause.

When an index is not needed

  • The table is small.
  • Most queries are expected to retrieve more than 2% – 4% of the rows.
  • The table is frequently updated (there are exceptions to this rule).
  • Columns are not often used in database queries.

Related