Engine Atlas

Cardinality & Histograms

Estimated vs Actual Rows
MySQL 8.4.102026-07-13
한국어
Learning guide

Question for this Lab

With the query and actual rows fixed, how much can the statistics state change the optimizer's row estimate?

Execution engine: MySQL 8.4.10
Who runs it?

One session executes the same SELECT under no-histogram, fresh-histogram, and stale-histogram statistics states.

What stays controlled?

The same skewed value distribution, predicate, actual rows, and statement result remain fixed.

Executed SQL
SELECT id, customer_id, sales_channel, ordered_at, total_cents
FROM order_events
WHERE sales_channel = 'PARTNER'
ORDER BY ordered_at DESC, id DESC
LIMIT 100;
What changes?

Distribution statistics, estimated plan rows, and estimate error change between variants.

What stays fixed?

The executed SQL, actual passing rows, and returned result stay the same across statistics variants.

Predict before tracing

What should you compare first across the three statistics states?

What should you compare first across the three statistics states?

Evidence mission

Open the estimate-error step of the Stale Histogram variant and see how far the estimate drifts when a histogram exists but its freshness does not match.

Where do you look?
Read estimated rows and actual rows side by side at the same Filter operator in the cardinality lens.
Screen to open
Stale Histogram · estimate error
What should you see?
Expected observation

The PARTNER mass 0.25 remembered by the stale histogram becomes filtered 25.00% and estimates 32,729 rows, while actual rows stay at 128. The histogram is present, the selected key stays null, and access type stays ALL.

Evidence boundary
Captured
estimated 32,729 and actual 128 rows for the stale variant
Captured
identical pre/post-mutation raw histogram buckets and timestamp
Checkpoint · explain from evidenceHow should estimated rows and actual rows be distinguished?Reveal answer and basis

Estimated rows are a pre-execution prediction based on statistics. Actual rows are captured execution observations. Compare them at the same operator without presenting either as the other.

Evidence boundary
Captured
estimated and actual rows for each variant
Core takeaway

Statistics do not change the result. When their freshness matches the data, they can reduce error between optimizer expectations and actual row flow.

Next connection

The next Lab compares how join algorithms organize outer/inner or build/probe row flow.

Review terms
cardinality estimateIntroduced in Lab 03
The optimizer's pre-execution prediction of how many rows will pass through an operator, based on statistics.
histogramIntroduced in Lab 03
Statistics that summarize a column's value distribution in buckets to improve selectivity estimates for skewed predicates.

01 · SOURCE

SQL

1 active fragmentMySQLLIMIT 100
SELECT id, customer_id, sales_channel, ordered_at, total_cents
FROM order_events
WHERE sales_channel = 'PARTNER'
ORDER BY ordered_at DESC, id DESC
LIMIT 100;
02 · FLOW

Native Plan

01 / 12
01/ 12