4.2.1: Indexing Overview
Indexing pre-calculates values. For example, the Inventory index aggregates the source quantity into the stock quantity. The Catalog Search Fulltext indexer pushes product data to ElasticSearch. And please don't forget the price indexer.
Without indexers, Magento would be very slow. Unusuably slow.
Unfortunately, very few developers know about indexing, let alone have made any changes to it. This section will make you familiar with the ins and outs of Magento indexing.
Let's look at the biggest concepts:
- Indexers are declared in
etc/indexer.xml. This implements
Mviewupdates individual rows when running in Index on Schedule mode. Indexers prepared for this are implement
Mviewrelies on Magento-created triggers which add a row into the applicable
- Indexers are run in three modes:
- What happens when a product is saved? This is where
Mviewinitiates an action when a row is changed. This would typically happen in MySQL and kick off an action in MySQL. However, Magento intercepts these requests. You will find numerous tables with the
_clsuffix. These tables contain records that need to be re-indexed. The
mview_statetable tracks these changes.
- Magento recommends that indexing happen on a schedule (every minute) and NOT after save. This means your cron process needs to be very reliable.
Let's discuss how indexers are kicked off. Cron is the most notable entry (although this is not always the case).
- This method iterates through the
- The rows to update are stored in tables ending in
mview_statestores the view IDs and the current
- When this runs, the current
version_idis compared with the
clis the abbreviation for
entity_id's that differ are indexed.
- Each indexer is loaded in
- If an indexer is marked as
statuscolumn, the entire index is rebuilt. Important: I've seen a number of cases where a 3rd-party module frequently marks an entire index as invalid. This is very bad for performance, and
mviewshould be used instead.
- The index is marked as
\Magento\Indexer\Model\Indexer::reindexAll. Note that if there is a shared index (the
catalog_product_categoryindexes, for example), the other one is suspended temporarily from reindexing.
There is nothing stopping you from directly calling an indexer process, like this:
You'll notice that the input parameters are different. In other words, you can't loop through all indexes and call
- Specific IDs: