Skip to content

feat: Use ClickHouse lightweight deletes#1040

Open
29antonioac wants to merge 1 commit into
elementary-data:masterfrom
29antonioac:feat/clickhouse-lightweight-deletes
Open

feat: Use ClickHouse lightweight deletes#1040
29antonioac wants to merge 1 commit into
elementary-data:masterfrom
29antonioac:feat/clickhouse-lightweight-deletes

Conversation

@29antonioac

@29antonioac 29antonioac commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

feat: Use lightweight deletes in ClickHouse

Summary

Replaces ALTER TABLE ... DELETE WHERE with DELETE FROM ... WHERE (lightweight delete) in the ClickHouse delete_and_insert macro.

Background

Elementary's delete_and_insert macro previously deleted rows in ClickHouse using ALTER TABLE ... DELETE WHERE, which triggers a heavy background mutation. Mutations are resource-intensive — they rewrite entire data parts and can lag behind inserts on large tables, causing contention and slow Elementary runs.

Lightweight deletes (DELETE FROM ... WHERE) became GA in ClickHouse 23.3. They work differently: rows are marked with a bitmask and resolved lazily at merge time, making the delete step significantly faster. Since dbt-clickhouse only supports ClickHouse 25.3+, every supported version has lightweight deletes on by default — no server configuration needed.

Changes

  • macros/utils/table_operations/delete_and_insert.sqlALTER TABLE ... DELETE WHEREDELETE FROM ... ON CLUSTER ... WHERE.

Testing

  • Tested against a ClickHouse instance running Elementary monitoring tables

Summary by CodeRabbit

  • Bug Fixes
    • Updated ClickHouse row deletion operations to use standard DELETE FROM statements while preserving existing row-matching behavior.
    • Insert operations remain unchanged.

@github-actions

Copy link
Copy Markdown
Contributor

👋 @29antonioac
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in the elementary repository.

@29antonioac
29antonioac requested a deployment to elementary_test_env July 21, 2026 17:31 — with GitHub Actions Waiting
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ebb0a841-dcfb-4163-a5a7-d4dbc8724de5

📥 Commits

Reviewing files that changed from the base of the PR and between ccb0de3 and e352b70.

📒 Files selected for processing (1)
  • macros/utils/table_operations/delete_and_insert.sql

📝 Walkthrough

Walkthrough

The ClickHouse implementation now generates DELETE FROM for row deletion instead of ALTER TABLE ... DELETE, while preserving the existing predicates, cluster clause, insert behavior, and return structure.

Changes

ClickHouse delete query generation

Layer / File(s) Summary
Generate ClickHouse DELETE statement
macros/utils/table_operations/delete_and_insert.sql
The macro replaces ALTER TABLE ... DELETE WHERE with DELETE FROM ... WHERE and retains the existing deletion predicates.

Estimated code review effort: 2 (Simple) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: switching ClickHouse deletes to lightweight deletes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant