Sign up to receive email updates and to hear what's going on with our magazine!
Indexing is a fundamental operation in Magento that greatly affect the performance of the store in several ways. Magento uses an Entity-Attribute-Value (EAV) database structure that often requires heavy database queries to retrieve simple results. Keeping this in mind, Magento developers have implemented index tables that query and store all the data into a single table structure, allowing Magento to query the single Index table rather than joining through complex JOIN queries that span multiple tables.
In simpler terms, indexing does not alter the data in the database. It just transfers the data about the users, products, and categories into a more efficient table system that significantly improves the speed and effectiveness of the store. For this purpose, Magento uses several special objects called indexers. A recommended best practice in the case of indexing is to reindex after every modification in database’s data. For instance, when the price(s) change, it is best to reindex the change so that the storefront always display the latest price. Filing to reindex in this case could result in performance drop and in worst cases, cart abandonment.
To reindex in Magento 1 follow the procedure.
In the Admin Panel, go to System > Index Management, check all the indexes that you wish to reindex and then submit the request.
In Magento 2, you could follow almost a similar procedure. However, the great thing about Magento 2 is that it has an impressive system Command Line Interface (CLI) based system that is ideal for a large set of products.
Magento 1 includes an indexing script indexer.php, which is found in the MAGENTO_ROOT/shell folder. This shell script could be used to reindex Magento using SSH or CLI.
To try out the script, you need to have access to the SSH Terminal, and then cd to MAGENTO_ROOT/shell.
To get help from the indexer.php shell script, you will need to execute the command php indexer.php help. The following response will appear:
To check the status of all indexes, type php indexer.php --status. The result should be something like:
Each index has its index key that is used as a reference when reindexing in Magento. To get the list of indexers and their keys, you can use the php indexer.php info command:
To reindex a single index, run the php indexer.php --reindex [Index Option Code] command:
The above command can also be comma delimited for multiple indexers:
You can also initiate a blanket reindex ( reindexall) across the store. However, this is not a recommended practice because it could cause MySql/Server overload. Reindexall calls eight indexers in a row and the process of reindexing all indexers can cause database LOCK on some tables. The command php indexer.php --reindexall will reindex all the indexers at once:
Index Management is an essential activity of every Magento based online store. It is important that the store administrator(s) take out time to learn how to reindex Magento using SSH terminal.
I hope this post will prove helpful. Thanks for reading! Please leave a comment if you wish to ask a question or add to the discussion.
Fayyaz is a Magento Community Manager at Cloudways - A Managed Magento Hosting Platform. He writes about Magento Tutorials at Magenticians as well as share his knowledge with the Magento Community. Fayyaz is a food lover and enjoys driving. You can email him at firstname.lastname@example.org