Magento Index Management

Magento Index Management

Magento Index Management

Indexing is important for Magento 2 as for all systems that process large amounts of data in multiple tables. It facilitates platform’s performance. In this article, we are going to discuss the core aspects of Magento index management

What is indexing in Magento 2?

An index is a table of a certain format in a database. Magento index processing converts data to increase performance. It is necessary because the data which is required for an online store operation is stored in a complex structure of tables. For example, if you want to find out the current product price, it involves connecting and processing a lot of tables and their connections.

In their turn, indexes store partly processed and formatted data decreasing server load and increasing the store’s speed. However, indexing is required after any change of the data that this index is applied to.

Magento 2 Indexation Terminology

  • Dictionary is the original regular data entered into the system.
  • Index is the representation of the original data for optimized reading and searching. It should be updated when there are any changes in the dictionary.
  • Indexer is an object that creates and updates an index.

Magento 2 index update

In order to operate up-to-date data, indexes should be updated from time to time. There are three ways to do it:

  1. Scheduled updates (launched by cron);
  2. Magento index update on save (It is launched when the data has been edited and saved);
  3. Manual update (via terminal).

By the type of processed data, Magento reindex can be launched as:

  • Full reindex processes all the indexed data again. It can always be launched manually via console.
  • Partial reindex processes again only the data that has been changed.

Magento index management via admin panel

In the admin panel, you can control index modes and observe the current information about the indexes (System> Index Management).

In the Mode column, we can see how index is updated. In the Status column, we can see whether reindex is required (Reindex Required) or not required (Ready). In the Updated column, you can see the date of the latest update.

Index Status Tables in Database

The following tables in a database are used for index status storage:

  • indexer_state
  • mview_state

Mechanism of indexation by schedule, Mview

When there are any changes in the object of a database that the Magento 2 system has indexes for, a new trigger appears in the table with the _cl postfix if there is such a table. If there is no such table, a new one is generated. The mview.xml files are responsible for defining the data which changes will be tracked in the _cl (change log) table.

For example, Magento/Catalog/etc/mview.xml

From this extract, you can see that the catalog_category_product_cl will be created. It will contain the information about the changes in catalog_category_entity and catalog_category_entity_int tables.

All the change log tables are created by a certain INDEXER_TABLE_NAME + ‘_cl’ rule. The tables contain the version_id columns as autoincrement and entity_id that contains the object identifier that needs to be reindexed. For every table listed in the table nodes, three types of MYSQL AFTER triggers are created: INSERT, UPDATE, DELETE.

The Mview component checks version_id in the *_cl tables if it is different from the one stored in the mview_state table. If the numbers are different, reindex launches.

Partial and complete indexation

Here we are going to discuss partial and complete indexation in Magento 2.

Partial indexation

Partial indexation updates indexes only in the objects that were modified. Partial indexation occurs both with Update on Save and Update by Schedule index modes. It is an indexation type where the change log tables are used that we described above.

Complete indexation

Complete indexation is required by some extensions in Magento 2 as some indexes may become invalid. Complete indexation launches by cron schedule or manually.

Copyright © 2024 Tridhya Tech Limited, Inc. All rights reserved.