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

Create a new incremental_substrategy for insert_overwrite and microbatch #1415

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

Conversation

borjavb
Copy link
Contributor

@borjavb borjavb commented Nov 27, 2024

resolves dbt-labs/dbt-adapters#527
docs dbt-labs/docs.getdbt.com/#

Problem

By default, we are using a MERGE operation when running an insert_overwrite or microbatch operation. But this is not the most performant solution. In fact, we have different options with their pros and cons. Currently we only rely on merge that is not the best performant solution and it doesn't allow fully parallelism for microbatch operations.

image

Solution

In this PR we propose adding a new incremental_substrategy for microbatch and insert_overwrite that will allow the user to select the best logic based on their needs.

Additionally, based on experience the best combo I've seen is:

  • For static partitions: delete+insert without a transaction to enable full parallelism
  • For dynamic partitions: bq copy

For that reason, we can add an additional optimised option that will run the best operation available (and that can be updated in the future if needed)

{{
    config(
        incremental_strategy={
                               "insert_overwrite",
                               "microbatch"
                              },
        incremental_substrategy={
                                 'merge', -- by default if no substrategy is specified
                                 'copy_partitions', -- same as defined in partitions_by
                                 'delete+insert', 
                                 'optimised' -- if partitions is defined (static), used delete+insert, if not (dynamic), use copy partitions
                                 },
       ...
    )
}}

We could force every user to use the optimised by default with the new release, but I just feel unease given that merge has been the default for ever and people might have built logics assuming this behaviour...?

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

@cla-bot cla-bot bot added the cla:yes label Nov 27, 2024
@borjavb borjavb changed the title Draft test Draft example of insert_overwrite with a new sub optimization function Nov 28, 2024
@borjavb borjavb force-pushed the insert-overwrite-opt branch 6 times, most recently from 25e45c7 to 16be393 Compare December 30, 2024 09:31
fixtures

Create Features-20241229-174752.yaml
@borjavb borjavb force-pushed the insert-overwrite-opt branch 2 times, most recently from 6580895 to d2e321a Compare December 30, 2024 12:31
@borjavb borjavb changed the title Draft example of insert_overwrite with a new sub optimization function Create a new incremental_substrategy for insert_overwrite and microbatch Dec 31, 2024
@borjavb borjavb marked this pull request as ready for review December 31, 2024 13:49
@borjavb borjavb requested a review from a team as a code owner December 31, 2024 13:49
@borjavb borjavb force-pushed the insert-overwrite-opt branch from d2e321a to 5893789 Compare January 17, 2025 19:36
@borjavb borjavb force-pushed the insert-overwrite-opt branch from 06baa78 to 241119a Compare January 24, 2025 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Optimize incremental 'insert_overwrite' strategy
1 participant