Skip to content
intermediate Phase 67 · Indexer System

Reindexing — Full, Partial, and Performance

Reindexing in Magento 2: full reindex, partial reindex, reindex performance optimization, and debugging reindex issues

45m
1 problems
Topic Progress 0%

Full Reindex

Full Reindex Command

# Reindex all indexers
php bin/magento indexer:reindex

# Reindex specific indexer
php bin/magento indexer:reindex catalog_product_price

# Reindex specific product
php bin/magento indexer:reindex catalog_product_price 123

What Full Reindex Does

  1. Clears all index data
  2. Rebuilds from source tables
  3. Updates flat tables / search index
  4. Marks indexer as 'valid'

Full Reindex Performance

# Time full reindex
time php bin/magento indexer:reindex

# With verbose output
php bin/magento indexer:reindex -vvv

Full Reindex for Large Catalogs

# For very large catalogs, run indexer-specific
php bin/magento indexer:reindex catalog_product_flat
php bin/magento indexer:reindex catalog_category_product
php bin/magento indexer:reindex catalog_product_price
php bin/magento indexer:reindex catalogsearch_fulltext

When to Full Reindex

  • After theme/layout changes
  • After attribute changes
  • After data migration
  • After module install/uninstall
  • When index is corrupted

Partial Reindex

Reindex by IDs

# Reindex specific products
php bin/magento indexer:reindex catalog_product_price 101 102 103

Programmatic Partial Reindex

namespace Vendor\Module\Service;

use Magento\Framework\Indexer\IndexerRegistry;

class IndexService
{
    public function __construct(
        private IndexerRegistry $indexerRegistry
    ) {}

    public function reindexProduct(int $productId): void
    {
        $indexer = $this->indexerRegistry->get('catalog_product_price');
        $indexer->reindexRow($productId);
    }

    public function reindexProducts(array $productIds): void
    {
        $indexer = $this->indexerRegistry->get('catalog_product_price');
        $indexer->reindexList($productIds);
    }
}

Changelog-Based Reindex

Scheduled mode tracks changes in changelog tables:

-- Check pending changes
SELECT * FROM catalog_product_price_cl
ORDER BY updated_at DESC;

-- Process changelog
php bin/magento cron:run --group index

Batch Reindex

// Batch reindex for performance
$batchSize = 500;
$chunks = array_chunk($productIds, $batchSize);

foreach ($chunks as $chunk) {
    $indexer->reindexList($chunk);
}

Reindex Performance

Performance Metrics

-- Reindex duration
SELECT
    indexer_id,
    updated_at,
    TIMESTAMPDIFF(SECOND, LAG(updated_at) OVER (ORDER BY updated_at), updated_at) as duration
FROM indexer_state
WHERE indexer_id = 'catalog_product_price';

Optimization Techniques

# Increase PHP memory for reindex
php -d memory_limit=2G bin/magento indexer:reindex

# Run reindex with production mode
php bin/magento deploy:mode:set production

# Disable unnecessary modules during reindex
php bin/magento module:disable Vendor_Module

Parallel Reindexing

# Run multiple indexers in parallel
php bin/magento indexer:reindex catalog_product_flat &
php bin/magento indexer:reindex catalog_category_product &
php bin/magento indexer:reindex catalog_product_price &
wait

Database Optimization

-- Optimize tables before reindex
OPTIMIZE TABLE catalog_product_entity;
OPTIMIZE TABLE catalog_product_entity_int;

-- Increase innodb_buffer_pool_size
SET GLOBAL innodb_buffer_pool_size = 2147483648;

Reindex Debugging

Common Reindex Issues

Issue Symptom Fix
Memory exhausted PHP fatal error Increase memory_limit
Timeout Long-running reindex Optimize queries
Lock wait timeout Deadlock during save Reduce concurrent saves
Invalid data Incorrect index output Check source data

Debug Commands

# Check indexer status
php bin/magento indexer:status

# Check detailed info
php bin/magento indexer:info catalog_product_price

# Reset stuck indexer
php bin/magento indexer:reset catalog_product_price

# Force reindex
php bin/magento indexer:reindex catalog_product_price -f

SQL Debugging

-- Check index validity
SELECT * FROM indexer_state WHERE status != 'valid';

-- Check changelog size
SELECT
    TABLE_NAME,
    TABLE_ROWS,
    DATA_LENGTH
FROM information_schema.TABLES
WHERE TABLE_NAME LIKE '%_cl';

-- Monitor reindex progress
SHOW PROCESSLIST;

Log Analysis

# Check reindex logs
grep -i reindex var/log/system.log

# Check for errors
grep -i error var/log/exception.log | grep -i index

Production Checklist

# Before reindex
1. php bin/magento maintenance:enable
2. Backup database

# Reindex
3. php bin/magento indexer:reindex

# After reindex
4. php bin/magento cache:clean
5. php bin/magento maintenance:disable

Practice Problems

0 / 1 solved
Slow Reindex

Full reindex takes 2 hours on a 100k product catalog. Optimize the reindex process.

Quiz

1. What does a full reindex do?

Question 1 options

2. How do you reindex a specific product?

Question 2 options

3. What table tracks pending reindex changes?

Question 3 options

4. What should you do before reindexing in production?

Question 4 options

Flashcards

Question

How to full reindex?

Answer

php bin/magento indexer:reindex

Question

How to reindex specific IDs?

Answer

php bin/magento indexer:reindex indexer_name id1 id2

Question

What tracks partial reindex changes?

Answer

Changelog tables with _cl suffix

Question

How to reset a stuck indexer?

Answer

php bin/magento indexer:reset indexer_name

Question

What to do before production reindex?

Answer

Enable maintenance mode, backup database

Revision Notes

Key Takeaways

  • 1. Full reindex clears and rebuilds all index data
  • 2. Partial reindex processes specific IDs or changelog entries
  • 3. Increase memory_limit for large catalog reindex
  • 4. Use batch reindexing for performance with large datasets
  • 5. Enable maintenance mode during production reindex
  • 6. Monitor with indexer:status and SQL queries on indexer_state

Interview Tips

  • Explain the difference between full and partial reindex
  • Describe how changelog-based reindexing works
  • Discuss optimization techniques for large catalogs
  • Know the production reindex checklist

Cheat Sheet

Reindexing Cheat Sheet

Full reindex:
php bin/magento indexer:reindex

Partial reindex:
php bin/magento indexer:reindex indexer_name id1 id2

Programmatic:

$indexer->reindexRow($id);
$indexer->reindexList($ids);
$indexer->reindexFull();

Performance:

  • Increase memory_limit
  • Batch reindex (500 per batch)
  • Optimize tables before reindex
  • Run indexers in parallel

Debug:

  • indexer:status
  • indexer:reset indexer_name
  • Check changelog table size