cockroachdb / cockroachdb/cockroach

sql: handle the partitioned spans for "fixing stats misestimates"

Open
#168,093 0 comments 0 reactions 0 assignees View on GitHub
A-sql-table-stats C-cleanup E-quick-win T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

In `makeScanEstimates` we populate different state which includes capturing the spans from the TableReader to be used to "fix misestimates" if the actual row count differs significantly from the estimated one. Currently, once we see a particular physical plan stage, we capture the necessary state and then we ignore all processors of the same stage. This behavior is problematic if we happened to partition the original spans (coming from `scanNode.spans`) at the range boundaries in a distributed plan - we will only capture spans assigned to a single node ignoring all others.

We should fix this behavior. One idea is to unconditionally track a map from stage ID to `scanNode.spans` (without a deep copy) during the physical planning so that we could just fetch that after the physical planning, when populating `scanStageEstimate` objects.

Another alternative would be to accumulate and merge all spans for the same stage after the physical planning, but that seems error-prone and redundant.

Jira issue: CRDB-62782

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.