Skip to content

Add DML table refresh method for table materializations (#641).#673

Merged
axellpadilla merged 1 commit into
dbt-msft:masterfrom
Benjamin-Knight:feat/#641-dml-table-refresh
May 20, 2026
Merged

Add DML table refresh method for table materializations (#641).#673
axellpadilla merged 1 commit into
dbt-msft:masterfrom
Benjamin-Knight:feat/#641-dml-table-refresh

Conversation

@Benjamin-Knight
Copy link
Copy Markdown
Collaborator

@Benjamin-Knight Benjamin-Knight commented May 20, 2026

Adds an opt-in table_refresh_method model config:

  • 'rename' (default): unchanged rename-swap behaviour.
  • 'dml': builds new data into a scratch table, then DELETE + INSERT into the target inside an explicit BEGIN/COMMIT TRANSACTION.

Under RCSI, the DML path keeps the target name resolvable throughout the swap so concurrent readers see the old data until COMMIT. The scratch table is built via a temp view so CTEs in the model SQL work, and the INSERT uses the target's physical column order so a reordered SELECT projection cannot misalign columns. Schema changes fall back to rename-swap for the affected run; the DML path also falls back when the existing relation is a view.
Fixes #641

Adds an opt-in `table_refresh_method` model config:
 - `'rename'` (default): unchanged rename-swap behaviour.
 - `'dml'`: builds new data into a scratch table, then DELETE + INSERT
   into the target inside an explicit BEGIN/COMMIT TRANSACTION.

Under RCSI, the DML path keeps the target name resolvable throughout
the swap so concurrent readers see the old data until COMMIT. The
scratch table is built via a temp view so CTEs in the model SQL work,
and the INSERT uses the target's physical column order so a reordered
SELECT projection cannot misalign columns. Schema changes fall back to
rename-swap for the affected run; the DML path also falls back when
the existing relation is a view (DML cannot operate on views).

Adds functional coverage for first run, subsequent run, schema-change
fallback, default vs explicit method config, invalid method validation,
clustered columnstore preservation, contract enforcement, models with
CTEs, view-to-table migration, column-order divergence, empty models,
and leftover-scratch cleanup.
@axellpadilla axellpadilla merged commit cc2f49d into dbt-msft:master May 20, 2026
53 checks passed
@Benjamin-Knight Benjamin-Knight deleted the feat/#641-dml-table-refresh branch May 21, 2026 08:41
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.

Table materialization rename-swap causes query failures under Read Committed Snapshot Isolation

2 participants