Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete insert patch 1 #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Delete insert patch 1 #1

wants to merge 2 commits into from

Conversation

ataft
Copy link
Owner

@ataft ataft commented Jan 26, 2024

resolves dbt-labs/dbt-adapters#150

Problem
The delete query for the 'delete+insert' incremental_strategy with 2+ unique_key columns is VERY inefficient. In many cases, it will hang and never return for deleting small amounts of data (<100K rows).

Solution
Improve the query by switching to a much more efficient delete strategy:

delete from table1
where (col1, col2) in (
select distinct col1, col2 from table1_tmp
)

Checklist
I have read the contributing guide and understand what's expected of me
I have run this code in development and it appears to resolve the stated issue
This PR includes tests, or tests are not required/relevant for this PR
This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX
This PR includes type annotations for new and modified functions

ataft added 2 commits January 25, 2024 14:59
changelog for Fix incremental delete+insert SQL
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.

[CT-3493] [Bug] unique_key list incremental model has performance issues on the delete phase
1 participant