Skip to content

feat(query): unify vacuum commands and execution - #20428

Open
SkyFan2002 wants to merge 16 commits into
databendlabs:mainfrom
SkyFan2002:refactor_vacuum
Open

feat(query): unify vacuum commands and execution#20428
SkyFan2002 wants to merge 16 commits into
databendlabs:mainfrom
SkyFan2002:refactor_vacuum

Conversation

@SkyFan2002

@SkyFan2002 SkyFan2002 commented Sep 2, 2026

Copy link
Copy Markdown
Member

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Unify table vacuum operations around the current VACUUM2 implementation and provide a consistent SQL command family.

This PR:

  • adds canonical VACUUM TABLE <table>, VACUUM TABLES [FROM <database>], and VACUUM ALL commands
  • keeps OPTIMIZE TABLE <table> PURGE as a compatibility alias for VACUUM TABLE
  • adds aliases for dropped-object vacuum operations
  • routes table, batch-table, automatic, and virtual-column cleanup through shared VACUUM2 execution helpers
  • applies consistent license, privilege, and queue handling to vacuum commands
  • preserves live table-tag references during VACUUM2 and removes expired tags on a best-effort basis
  • removes the obsolete Table::purge, legacy do_vacuum, old GC implementation, plans, interpreters, navigation helpers, and tests that only exercised those dead interfaces

Implementation

  • Introduce dedicated AST statements, plans, binders, and interpreters for the canonical vacuum commands.
  • Share VACUUM2 execution helpers between SQL interpreters, table functions, and automatic cleanup hooks.
  • Map the legacy OPTIMIZE TABLE ... PURGE syntax directly to VacuumTable, avoiding a second execution path.
  • Make batch commands skip unsupported table engines while retaining per-table error isolation.
  • Move table-tag protection into the active VACUUM2 path before deleting snapshots and segments.
  • Delete the legacy purge implementation after verifying that no production caller remains.

Compatibility and risk

  • OPTIMIZE TABLE ... PURGE remains accepted and uses the same VACUUM2 behavior as VACUUM TABLE.
  • Removed PURGE BEFORE/snapshot-limit interfaces belonged to the obsolete execution path and are no longer exposed by the simplified vacuum syntax.
  • The storage-sensitive paths are covered by execution tests for aliases, batch scope, transaction protection, chunked protected-segment reads, and table-tag references.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Not applicable

Validation performed:

cargo fmt --all
git diff --check
cargo test -p databend-enterprise-query --test it -- storages::fuse::operations::vacuum2
cargo test -p databend-query --test it --no-run
cargo test -p databend-enterprise-query --test it --no-run
cargo clippy -p databend-common-catalog \
  -p databend-common-storages-fuse \
  -p databend-common-storages-hive \
  -p databend-enterprise-vacuum-handler \
  -p databend-enterprise-query \
  -p databend-query --all-targets -- -D warnings

The VACUUM2 integration module completed with 9 passing tests. A repository-wide stale-symbol scan also found no remaining legacy do_vacuum, Table::purge, do_purge, or old GC module references.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

AI assistance

  • AI usage: An AI coding agent assisted with repository analysis, implementation and dead-code cleanup, regression tests, validation, and drafting this PR description.
  • Responsible human: @SkyFan2002
  • The responsible human has read every line of this diff and can explain each change

This change is Reviewable

@github-actions github-actions Bot added the pr-feature this PR introduces a new feature to the codebase label Sep 2, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: da66ac56d4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/query/service/src/interpreters/interpreter_table_vacuum.rs
Comment thread src/query/service/src/table_functions/fuse_vacuum2/vacuum2.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-feature this PR introduces a new feature to the codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant