interactivated blog

magento & ecommerce

How does Magento indexing work?

To understand fully how Magento indexing works, you need a crash course on database indexing in general. Indexing is basically a sorting method for records, or in this case, database fields. You can use this to find specific information, but most importantly, to update that information by assigning new values.

Now, various programming languages address this issue differently, as each one tries to either maximize efficiency or reduce the amount of disk space used. The way that fields are organized is just as important as the search method.

For example, a binary search is far superior in speed compared to a linear search. However, a binary search can only be performed on an already sorted field of block accesses.

Although indexing seems, and in fact is, quite complex, you don’t need a lot of programming experience to work it out if you’re using Magento. Here’s an overview of how Magento addresses PHP indexing.

Built-in Magento indexing

Magento uses 10 indexers to transform data from products or categories. Although this is enough for most basic e-commerce websites, the application also allows you to create your own custom indexers.

Because Magento indexing is not optimized for every potential situation, supplementing the default indexer list with your own may be needed. Especially when you customize a website in such a way that it requires advanced data searches during updates.

Components involved in indexing

1. Magento_indexer

This component is responsible for implementing the following actions: indexer declaration, indexer status, indexer running, indexer running mode configuration.

2. Magento\Framework\Mview

The Mview component is similar to MySQL’s “materialized view”. However, in the case of Magento, this function results in executing PHP code. This is different from SQL queries because it permits multiple queries to occur at the same time.

Indexing in Magento

As previously mentioned, there is a component that makes Magento indexing quite similar to MySQL database-level indexing. However, Magento is a lot more versatile and customizable when it comes to indexing.

The standard object indexing would normally be done on a large table that stores catalog products or categories. This is generally a fast way to perform searches, but there is an age-old problem to consider. Adding new attributes.

Attributes can be anything from a discount price or a color to adding an age range for certain toys or clothes. The way this is typically done is by adding a new column to the table. But what if only a handful of products have that new attribute? How do you then approach maintenance without slowing down the website?

Magento addresses this issue by splitting the classic table into smaller units that are easier to categorize. This level of flexibility allows for product categories and types to be better defined by merchants and website admins.

To further improve the performance, Magento uses another neat trick. This works if you start from the assumption that all the attributes have been clearly defined and a complete large table has been generated.

This allows Magento’s indexing to recreate the entire table at every change. Basically, when an attribute changes, say the price of T-shirt, the old table containing that information is obliterated in order to be generated again with the new value added, and everything else stays intact.

At the end of the day, this takes care of wasted resources spent on searching across multiple categories.

How Magento triggers reindexing

Based on the indexer status and indexing mode, the indexing mechanism triggers when needed. The value of an indexer status can be any of the following:

1. Valid

This means that no reindexing is required. The valid status appears when the data is synchronized.

2. Invalid

This means that the index requires an update as the original data was modified.

3. Working

This means that indexing is already in progress.

Now, there are two ways or modes for Magento to handle reindexing. You can choose between “Update on Save” and “Update by Schedule”.

The first option might make the browsing experience slightly slower, but it is the best way to ensure everything is up to date. The scheduled reindexing is done by what is called a cron job. It’s the standard PHP method of creating and executing various repetitive or scheduled tasks.

Both options must be set manually for Magento to take any action. This can be done by using the command line, but you can also do this by using the admin panel.

  • Go to Magento admin
  • Select system
  • Select index Management
  • Select the checkbox for indexers that you want to be affected by the updates
  • Go to actions list
  • Select indexing mode
  • Click submit

Best way to index in Magento

Whether you’re running a small online store or a large e-commerce website, manual indexing is still recommended. The Magento platform is very customizable but it’s not the fastest when it comes to making large updates.

One common issue with PHP-based indexing is that large updates can take too long. If the process takes too long, the script might end abruptly. This often causes data corruption and of course, your website will take a performance hit too.

Manual indexing lets you do one important thing. You get to choose a time of day when the website traffic is slower. This means you won’t ruin the user experience of your potential shoppers.

You can also choose to split an update across two days or two specific timeframes when traffic activity is at its lowest. This can considerably reduce the chances of the PHP script falling short and corrupting your data.

A final word

Although Magento doesn’t have the fastest indexing process, updates to the code over the past few years have certainly improved it. Magento is no longer as slow as it used to be and it still manages to maintain a level of flexibility that’s somewhat superior to that of classic MySQL indexing.

There are still some drawbacks in terms of automatic updates and you still have to add all your attributes to the table before you generate it. It’s by no means mandatory, but the extra work you put in beforehand will save you a lot of time and resources when attempting to do reindexing for your online store.

By interactivated • on January 16, 2019

Contact Us
Get in touch with a specialist
THE NETHERLANDS (HQ)
Herestraat 106, 9711LM,
Groningen (Netherlands)
+31 (0)50 711 9940
VAT: NL 852998521B01
Chamber of Commerce: 58348646
UKRAINE
Kostomarivs'ka 13,
61002, Kharkiv
SPAIN
Calle Jabea 18, 29631,
Benalmádena Costa (Malaga)

* Required Fields