What Are Indexers?
The Problem Indexers Solve
Without indexing, every product listing query would:
- JOIN multiple EAV tables
- Filter by attributes, categories, prices
- Sort by relevancy, price, name
- Calculate aggregates (count, sum)
This is slow for large catalogs.
How Indexers Work
Raw Data (EAV tables) -> Indexer -> Flat Table / Search Index
Indexers pre-compute and store results in flat tables optimized for reading.
Example: Catalog Product Flat
-- Without flat table (slow)
SELECT p.entity_id, eav_value.value
FROM catalog_product_entity p
JOIN catalog_product_entity_int eav_value ON ...
JOIN eav_attribute ON ...
WHERE eav_attribute.attribute_code = 'name'
AND ... (many more joins)
-- With flat table (fast)
SELECT * FROM catalog_product_flat_1
WHERE name LIKE '%widget%'
Index Performance Impact
| Operation | Without Index | With Index |
|---|---|---|
| Product listing | 500ms+ | 50ms |
| Search query | 2s+ | 200ms |
| Category load | 300ms+ | 30ms |
Magento Indexer Types
All Indexers
php bin/magento indexer:info
| Indexer | Code | Purpose |
|---|---|---|
| Catalog Product Flat | catalog_product_flat | Flat table for products |
| Category Products | catalog_category_product | Products per category |
| Product Price | catalog_product_price | Product prices |
| Product EAV | catalog_product_attribute | Product attributes |
| Product URL | catalog_product_url | Product URL rewrites |
| Catalog Category Flat | catalog_category_flat | Flat table for categories |
| Catalog Search | catalogsearch_fulltext | Full-text search index |
| Catalog Rule Product | catalogrule_product | Catalog price rules |
| Sales Rule | salesrule_rule | Cart price rules |
| Product Stock | cataloginventory_stock | Stock status |
| CMS Page | cms_page | CMS page index |
Viewing Indexer Status
php bin/magento indexer:status
+------------------------------------+---------+-----------+-----------+
| Indexer | Status | Update | Schedule |
+------------------------------------+---------+-----------+-----------+
| catalog_product_flat | Ready | Update | Schedule |
| catalog_category_product | Ready | Update | Schedule |
| catalog_product_price | Ready | Update | Schedule |
| catalogsearch_fulltext | Ready | Update | Schedule |
+------------------------------------+---------+-----------+-----------+
Indexer Information
# Detailed info about specific indexer
php bin/magento indexer:info catalog_product_price
# List all indexers
php bin/magento indexer:info
Indexer Architecture
Indexer Interface
All indexers implement Magento\Framework\Indexer\ActionInterface:
interface ActionInterface
{
public function executeFull();
public function executeList(array $ids);
public function executeRow($id);
}
Indexer Methods
| Method | Description |
|---|---|
| executeFull | Reindex everything |
| executeList | Reindex specific IDs |
| executeRow | Reindex single item |
Indexer State
-- Indexer state table
CREATE TABLE indexer_state (
indexer_id VARCHAR(128),
status VARCHAR(12), -- valid, invalid, working
updated_at TIMESTAMP
);
Index Data Storage
-- Flat product table example
CREATE TABLE catalog_product_flat_1 (
entity_id INT,
name VARCHAR(255),
price DECIMAL(12,2),
sku VARCHAR(255),
-- ... flattened attributes
);
Multi-Store Indexing
Each store view gets its own flat table:
catalog_product_flat_1 (store 1)
catalog_product_flat_2 (store 2)
catalog_product_flat_3 (store 3)
Managing Indexer Status
Indexer Modes
# Check current mode
php bin/magento indexer:show-mode
# Set to real-time (update on save)
php bin/magento indexer:set-mode realtime catalog_product_price
# Set to schedule (update by schedule)
php bin/magento indexer:set-mode schedule catalog_product_price
Indexer Status Commands
# Check status of all indexers
php bin/magento indexer:status
# Check specific indexer
php bin/magento indexer:status catalog_product_price
# Get detailed info
php bin/magento indexer:info
# Reset indexer state
php bin/magento indexer:reset catalog_product_price
Reindex Commands
# Reindex all
php bin/magento indexer:reindex
# Reindex specific
php bin/magento indexer:reindex catalog_product_price
# Reindex specific product
php bin/magento indexer:reindex catalog_product_price 123
Monitoring Indexer Health
-- Check index validity
SELECT indexer_id, status, updated_at
FROM indexer_state
WHERE status != 'valid';
-- Check last update time
SELECT indexer_id, updated_at
FROM indexer_state
ORDER BY updated_at;
Practice Problems
Products are not appearing in search results after being saved. Diagnose and fix the indexing issue.
Quiz
1. What is the primary purpose of indexers?
2. What command shows all indexer statuses?
3. What does executeFull do in an indexer?
4. How many flat tables does catalog_product_flat create for 3 store views?
Flashcards
Question
What is an indexer?
Click to reveal answer
Answer
A system that pre-computes query results and stores them in optimized flat tables
Question
What are the two indexer modes?
Click to reveal answer
Answer
Real-time (update on save) and Schedule (update by cron)
Question
How to reindex all indexers?
Click to reveal answer
Answer
php bin/magento indexer:reindex
Question
What does executeList reindex?
Click to reveal answer
Answer
Specific entity IDs passed as parameter
Question
Where is indexer status stored?
Click to reveal answer
Answer
indexer_state table with status (valid/invalid/working)
Revision Notes
Key Takeaways
- 1. Indexers pre-compute data into flat tables for fast queries
- 2. Two modes: Real-time (update on save) and Schedule (cron-based)
- 3. Each indexer implements ActionInterface: executeFull, executeList, executeRow
- 4. Multi-store setups create separate flat tables per store view
- 5. Monitor with indexer:status and reindex with indexer:reindex
- 6. Invalid indexes need reindexing to show correct data
Interview Tips
- • Explain what indexers are and why they improve performance
- • List the main Magento indexers and their purposes
- • Compare real-time vs scheduled indexing modes
- • Describe how to monitor and fix indexer issues
Cheat Sheet
Indexers Cheat Sheet
Modes:
- Real-time: updates on save
- Schedule: updates via cron
Key indexers:
- catalog_product_flat: product flat table
- catalog_category_product: category-product mapping
- catalog_product_price: price calculations
- catalogsearch_fulltext: search index
Commands:
- indexer:status — check all
- indexer:reindex — reindex all
- indexer:set-mode — change mode
- indexer:info — detailed info
Status: valid, invalid, working