MySQL Index Type

InnoDB Secondary Indexes in MySQL: How It Works and When to Use It

A secondary index stores its key and primary-key value. The engine follows that primary key to the clustered row unless the index covers the query.

What Is a InnoDB Secondary Indexes in MySQL?

A secondary index stores its key and primary-key value. The engine follows that primary key to the clustered row unless the index covers the query.

How the InnoDB Secondary Indexes Algorithm Works

A secondary index stores its key and primary-key value. The engine follows that primary key to the clustered row unless the index covers the query.

Diagram showing the InnoDB Secondary Indexes lookup algorithm
Conceptual InnoDB Secondary Indexes algorithm. Exact behavior depends on the database version and query plan.

When to Use InnoDB Secondary Indexes

Selective filters, joins, and sorts not served by the primary key.

How to Create a MySQL InnoDB Secondary Indexes

Review data quality, existing structures, feature support, build time, and deployment requirements before creating an index on a production table.

CREATE INDEX orders_customer_idx ON orders (customer_id);

InnoDB Secondary Indexes Query Example

This example demonstrates the matching query shape. Check the execution plan to confirm that the engine can use the index.

SELECT id, total FROM orders WHERE customer_id = 42;

Queries Supported by InnoDB Secondary Indexes

Selective filters, joins, and sorts not served by the primary key. A similar-looking predicate may not use the same access path; operators, expressions, key order, and data type all matter.

Read Performance, Storage, and Write Costs

Adds space and can require an extra clustered lookup; every extra index increases DML work. Indexes reduce some search work but require storage and add maintenance to writes.

InnoDB Secondary Indexes Limitations and Common Mistakes

Too many low-value indexes slow writes; long keys can be large.

Do not assume that an index being present means the optimizer chose it or that the query became selective.

How to Measure and Tune InnoDB Secondary Indexes

Use EXPLAIN to verify covering, rows, and whether a composite index can replace redundant keys.

Compare representative plans and timings before and after, including concurrent writes and realistic data volumes.

InnoDB Secondary Indexes Questions

Will the database always use this index?

No. The optimizer weighs selectivity, estimated costs, statistics, cache state, and the amount of data returned.

What should I verify before production?

Confirm version support, query compatibility, write overhead, build/rollback procedures, and index behavior during backup and recovery.

Official MySQL Index Documentation

Check MySQL 8.4 Reference Manual: Optimization and Indexes for release-specific requirements and supported operators.