Fix(mssql): Use truncate+insert for FULL models instead of merge#4531
Merged
Fix(mssql): Use truncate+insert for FULL models instead of merge#4531
Conversation
erindru
commented
May 26, 2025
| if not where or where == exp.true(): | ||
| # this is a full table replacement, call the base strategy to do DELETE+INSERT | ||
| # which will result in TRUNCATE+INSERT due to how we have overridden self.delete_from() | ||
| return EngineAdapter._insert_overwrite_by_condition( |
Collaborator
Author
There was a problem hiding this comment.
super(EngineAdapter, self) threw an exception and super(EngineAdapterWithIndexSupport, self) returned the _insert_overwrite_by_condition method from InsertOverwriteWithMergeMixin instead of from EngineAdapter.
So I worked around this by making a direct call to EngineAdapter
georgesittas
approved these changes
May 26, 2025
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.
Addresses issue #4472
This PR:
delete_from()to useTRUNCATEif there is no WHERE clause. This works because unlike many other databases, truncate works within a transaction on MSSQL and is more efficient than usingDELETEDELETE+INSERTstrategy instead ofMERGEif_insert_overwrite_by_conditionis called without a condition._insert_overwrite_by_conditionis used byreplace_table()which is how theFULLmaterialization strategy is implemented.The net result is that full data replacements in existing tables become a lot more efficient