Skip to content

[spark] Cover the zero a truncation reports surviving a later ANALYZE - #9350

Closed
sundapeng wants to merge 1 commit into
apache:masterfrom
sundapeng:upstream/analyze-after-truncate
Closed

[spark] Cover the zero a truncation reports surviving a later ANALYZE#9350
sundapeng wants to merge 1 commit into
apache:masterfrom
sundapeng:upstream/analyze-after-truncate

Conversation

@sundapeng

Copy link
Copy Markdown
Member

Purpose

A truncation reports an exact zero for every partition it emptied. ANALYZE measures a partition
and writes down what it found. Nothing pinned what the second does to the first.

The failure would be silent in the direction that matters. Statistics carry UNKNOWN as a negative
value, so a zero degraded back to unknown does not read as "this partition is empty" but as "nobody
measured it", and a consumer that guards on the value being known skips the partition instead of
planning for an empty one. An exact zero is a measurement; it should not be reachable to lose it by
measuring again.

Tests

CatalogManagedPartitionAnalyzeTest: measure a partition, truncate it, then run COMPUTE STATISTICS NOSCAN and a full COMPUTE STATISTICS over it, asserting the row count and file count are still
zero rather than unknown.

The case needs TRUNCATE TABLE (#9330) and ANALYZE TABLE (#9298) in the same tree, which is why
it could not ride along with either of them. Both are in master now.

API and Format

No production change; test only.

A truncation reports an exact zero for the partitions it emptied. ANALYZE measures a partition and
writes what it found. Nothing pinned what the second does to the first, and the failure would be
silent in the direction that matters: a zero degraded back to unknown reads as "nobody measured
this", so a planner that guards on the value being known starts skipping the partition instead of
knowing it is empty.
The case truncates a measured partition and then runs both forms of ANALYZE over it, asserting the
zero is still a zero. It needs `TRUNCATE TABLE` and `ANALYZE TABLE` together, which is why it could
not go in with either of them.
@sundapeng
sundapeng marked this pull request as draft August 22, 2026 02:17
@sundapeng
sundapeng marked this pull request as ready for review August 22, 2026 02:17
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@sundapeng