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

[Microbatch] Optimizations: use view for temp relation + remove using clause during delete statement #1192

Merged
merged 6 commits into from
Nov 6, 2024

Conversation

MichelleArk
Copy link
Contributor

@MichelleArk MichelleArk commented Sep 26, 2024

resolves #1228
docs dbt-labs/docs.getdbt.com/# N/A

Problem

Microbatch performance is underwhelming for dbt-snowflake! A couple underlying reasons:

  1. Microbatch largely inherits from delete+insert strategy in snowflake, which has been optimized to use a temp view instead of table. However, microbatch is still using a temp table! More details: https://docs.getdbt.com/reference/resource-configs/snowflake-configs#temporary-tables
  • Note that it is always safe to do so for microbatch since there is no unique_key necessary
  1. The using clause is unnecessary in the microbatch delete statement, because microbatch does not require a merge key and the where clause is sufficient for a safe deletion.

Solution

  1. Apply temp view optimization to microbatch. Was just a matter of extending a couple if statements that only checked for insert+delete previously
  2. Remove extraneous using clause

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 Sep 26, 2024
Copy link
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the dbt-snowflake contributing guide.

@MichelleArk MichelleArk changed the title optimization: use view for temp relation for microbatch [Microbatch] Optimizations: use view for temp relation + remove using clause during insert Nov 1, 2024
@MichelleArk MichelleArk changed the title [Microbatch] Optimizations: use view for temp relation + remove using clause during insert [Microbatch] Optimizations: use view for temp relation + remove using clause during delete statement Nov 1, 2024
@MichelleArk MichelleArk marked this pull request as ready for review November 5, 2024 17:03
@MichelleArk MichelleArk requested a review from a team as a code owner November 5, 2024 17:03
Copy link
Contributor

@QMalcolm QMalcolm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! :shipit:

{% elif strategy == "delete+insert" and unique_key is none %}
{% elif strategy in ["delete+insert", "microbatch"] and unique_key is none %}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 This is a greeeeaaaat catch! Nice!

@MichelleArk MichelleArk merged commit 01dbd70 into main Nov 6, 2024
41 checks passed
@MichelleArk MichelleArk deleted the microbatch-use-temp-view branch November 6, 2024 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants