Databases 7 min read

How Index Pushdown Cuts Unnecessary Table Lookups in MySQL

This article explains MySQL's table‑lookup (回表) process, the difference between primary‑key and secondary indexes, and how the index‑pushdown feature introduced in MySQL 5.6 reduces unnecessary lookups by filtering rows directly in the index.

ITPUB
ITPUB
ITPUB
How Index Pushdown Cuts Unnecessary Table Lookups in MySQL

Table Lookup (回表操作)

In MySQL any query that uses a secondary index must retrieve the full row from the primary key after locating the matching key. This two‑step process is called a table lookup.

Primary Key Index

In InnoDB the primary key is stored as a clustered B+‑tree. Internal nodes contain only the key values; leaf nodes store the complete row.

Secondary (Non‑Primary) Index

Secondary indexes are also B+‑trees, but their leaf nodes store only the primary‑key value of each row.

Table Lookup Process

When a query searches a secondary index, MySQL first finds the primary‑key value in the leaf node, then uses that value to fetch the full row from the primary‑key index.

Behavior in MySQL < 5.6 (no index pushdown)

Before MySQL 5.6 each row that satisfied the secondary‑index predicate required a table lookup, causing an extra tree traversal for every matching row.

Behavior in MySQL ≥ 5.6 (index pushdown)

From MySQL 5.6 onward the engine can evaluate additional predicates that are stored in the secondary index (e.g., sex = 1) while scanning the index. Only rows that satisfy those predicates proceed to the table‑lookup step, reducing the number of lookups.

Illustrative Example

Consider a table user with columns id (auto‑increment primary key), name, sex, height, age. A composite index (name, sex) exists. To find all male users named “王” the SQL is:

SELECT * FROM user WHERE name = '王' AND sex = 1;

Using the left‑most prefix rule, the secondary index is first scanned for name='王'. The leaf nodes return the primary‑key values. In MySQL < 5.6 each primary‑key lookup is performed, then the sex condition is checked, resulting in many table lookups.

With index pushdown (MySQL ≥ 5.6) the engine applies the sex = 1 filter while scanning the secondary index, so only rows that satisfy both conditions are fetched from the primary‑key index, halving the number of lookups in this example.

Summary

Table lookup is required when the needed column is not stored in the secondary index leaf; the engine must fetch the full row via the primary key.

Index pushdown (available from MySQL 5.6) reduces unnecessary lookups by filtering rows using columns present in the secondary index before performing the table lookup.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

InnoDBMySQLDatabase OptimizationTable LookupIndex Pushdown
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.