feat: full_refresh_build config with prebuilt in-place rebuild path - #750
Merged
axellpadilla merged 2 commits intoJul 23, 2026
Merged
Conversation
Add a full_refresh_build model config. `prebuilt` rebuilds a table in
place - drop the old table, recreate it empty with its clustered design
(as_columnstore CCI or the clustered index from the indexes config), then
bulk-load via INSERT WITH (TABLOCK). No intermediate copy or rename swap,
so peak rebuild disk is ~1x instead of ~2x. Default heap_then_index is
unchanged.
- Applies only under --full-refresh and on first builds; normal runs keep
the configured refresh. Takes precedence over table_refresh_method: dml.
- Drops the table, so {{ this }} self-references must be guarded by
is_incremental(); the adapter fails on an unguarded self-reference
before dropping anything.
- Full refreshes mark the target with a dbt_full_refresh_incomplete
extended property until they complete, so a later normal incremental
over a failed refresh errors instead of appending onto stale data.
Builds on the indexes feature shipped in v1.10.1.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
axellpadilla
approved these changes
Jul 22, 2026
axellpadilla
left a comment
Collaborator
There was a problem hiding this comment.
I believe we should open an issue about reviewing quoting and standarization around that, but for this one we just need @level0name = N'{{ escape_single_quotes(relation.schema) }}',
@level1name = N'{{ escape_single_quotes(relation.identifier) }}'
The prebuilt full-refresh path had two related defects: 1. The first-build branch (existing_relation is none) issued a bare CREATE / SELECT ... INTO with no drop, so a stale relation cache (table exists in the DB but absent from the cache, e.g. an orphaned concurrent writer created it after the run's cache snapshot) collided with Msg 2714. Add an OBJECT_ID-guarded DROP inside sqlserver__create_table_as_prebuilt so the create is idempotent for both callers and both build branches; drop the fragile "callers drop first" contract. 2. The prebuilt path lands the table via raw SQL, not a cache-maintaining adapter method, so the rebuilt relation was never registered in dbt's cache (and on full-refresh, drop_relation removed it and nothing re-added it). Call adapter.cache_added(target_relation) after the main statement in incremental.sql and table.sql to keep the cache in sync. Also escape_single_quotes the schema/identifier in the sp_add/dropextendedproperty N'...' literals and the new OBJECT_ID literal. Add TestFullRefreshBuildStaleCache: a pre_hook creates the physical table after existing_relation is snapshotted from the cache but before the prebuilt create, deterministically reproducing the drift. Verified the tests fail without the macro fix (Msg 2714) and pass with it. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
Author
|
Agreed about the single quote escaping, added that and a bug fix for an issue I ran across. |
Collaborator
|
@Benjamin-Knight I suspect building columstore before change should be the default, as other actions are focused on swaps and prebuild |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a full_refresh_build model config offering a lower-disk full-refresh rebuild path. Builds on the indexes feature shipped in v1.10.1. Resolve #749
heap_then_indexprebuiltINSERT WITH (TABLOCK). No intermediate copy, no swap → ~1x peak disk instead of ~2x.Behaviour
Performance: parallel index build vs. serial insert (edition matters)
prebuilt swaps the default's post-load CREATE INDEX for an INSERT WITH (TABLOCK) into the existing index:
The ~1x peak-disk benefit holds on every edition; only the time cost is edition-dependent.
Testing