Skip to content

Fix UpdateStatistics.remove_statistics overwriting prior queued updates - #4488

Merged
Fokko merged 1 commit into
apache:mainfrom
xgbtxy:fix/update-statistics-append-removals
Nov 30, 2026
Merged

Fokko merged 1 commit into
apache:mainfrom
xgbtxy:fix/update-statistics-append-removals

Conversation

@xgbtxy

@xgbtxy xgbtxy commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

UpdateStatistics.remove_statistics() assigned self._updates = (RemoveStatisticsUpdate(snapshot_id=snapshot_id),) instead of appending via +=. As a result, chaining set_statistics(...).remove_statistics(...), using the context manager pattern shown in the UpdateStatistics and Table.update_statistics() docstrings, or calling remove_statistics() multiple times in one update silently discarded all previously queued updates.

This change switches self._updates = (...) to self._updates += (...) in UpdateStatistics.remove_statistics(), preserving all pending statistics updates in the batch.

Are these changes tested?

Yes. Added end-to-end catalog tests in tests/table/test_update_statistics.py (no mocks, running across the memory, sql, and sql_without_rowcount catalog fixtures):

  • test_update_statistics_set_and_remove_in_one_update (chained, context-manager, and reverse order)
  • test_update_statistics_multiple_removals_in_one_update
  • test_update_statistics_set_and_remove_in_transaction

Confirmed all 9 parametrized test cases fail prior to the fix (9 failed) and pass after the fix (9 passed), along with tests/table/test_statistics.py and ruff / ty / codespell checks.

Are there any user-facing changes?

Yes. Calling remove_statistics() after set_statistics() or another remove_statistics() in the same UpdateStatistics batch or context manager now preserves and commits all queued updates instead of silently dropping earlier ones.

UpdateStatistics.remove_statistics() assigned self._updates = (...)
instead of appending via self._updates += (...), silently discarding
any preceding set_statistics() or remove_statistics() calls queued in
the same UpdateStatistics batch or context manager.

Append the RemoveStatisticsUpdate to self._updates so chained and
context-manager statistics updates preserve all pending operations,
matching the documented UpdateStatistics behavior.
Copilot AI balanced review requested due to automatic review settings November 25, 2026 16:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@Fokko
Fokko self-requested a review November 30, 2026 17:40

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @xgbtxy, nice find and thorough tests 🙌 LGTM!

@Fokko
Fokko added this pull request to the merge queue Nov 30, 2026
Merged via the queue into apache:main with commit d86ec6f Nov 30, 2026
20 checks passed
Sign up for free to 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.

3 participants