Improve DBT Incremental Performance on Snowflake using Custom Incremental Strategy

May 29, 2025

Data

The following presents how to improve the performance of the DBT built-in delete-insert incremental strategy on snowflake so we can control snowflake query costs. It is broken down into:

  1. Defining the problem, with supporting performance statistics

  2. Desired solution requirements

  3. Solution implementation, with supporting performance statistics

TL;DR

We implemented a DBT custom incremental strategy, along with incremental predicates to improve snowflake query performance:

  • Reduced MBs scanned by ~99.68%

  • Reduced micro-partitions scanned by ~99.53%

  • Reduced query time from 19 seconds to 1.3 seconds

Less data is being scanned, so the snowflake warehouse is waiting less time on I/O, so the query completes faster.

Disclaimer

Custom incremental strategies and incremental predicates are more advanced uses of DBT for incremental processing. But I suppose that’s where you have the most fun, so lets get stuck in!

Problem

When using the DBT built-in delete-insert incremental strategy on large volumes of data, you can get inefficient queries on snowflake when the delete statement is executed. This means queries take longer and increase warehouse costs.

Taking an example target table:

  • With ~458 million rows

  • Is ~26 GB in size

  • Has ~2560 micro-partitions

With a DBT model that:

  • Is running every 30 minutes

  • Typically there are ~100K rows to merge into the target table on every run. As data can arrive out-of-order, a subsequent run will pick these up, but means it can include rows already processed.

With DBT model config:

  - name: model_name
    config:
      materialized: "incremental"
      incremental_strategy: "delete+insert"
      on_schema_change: "append_new_columns"
      unique_key: ["dw_order_created_skey"] -- varchar(100)
      cluster_by: ["to_date(order_created_at)"]

Default delete SQL generated by DBT, before it inserts data in the same transaction:


Performance Statistics

To find the rows in the target table to delete with the matching dw_order_created_skey (see node profile overview image below), snowflake has to:

  • Scan ~11 GB of the target table

  • Scan all ~2560 micro-partitions

  • Query takes ~19 seconds

Why? - The query is not filtering on order_created_at to allow snowflake to use the clustering key of to_date(order_created_at) to find the matching rows to delete.

Query plan


delete query plan


node profile overview

Desired Solution

To limit the data read in the target table above. We can make use of incremental_predicates in the model config. This will add SQL to filter the target table.

DBT model config:

  - name: model_name
    config:
      materialized: "incremental"
      incremental_strategy: "delete+insert"
      on_schema_change: "append_new_columns"
      unique_key: ["dw_order_created_skey"]
      cluster_by: ["to_date(order_created_at)"]

Issues with this

  • The incremental_predicates docs states dbt does not check the syntax of the SQL statements, so it does not change anything in the SQL.

  • We get an error when it executes on snowflake: Object 'DBT_INTERNAL_SOURCE' does not exist or not authorized.

  • We cannot hardcode the snowflake table name in the incremental_predicates, as its dynamically generated by DBT.

Solution Implementation

We need to:

  • Do some pre-processing on each element of incremental_predicates to replace DBT_INTERNAL_SOURCE with actual source_temp_table so SQL like the below is generated by DBT for better performance:


  • Continue to call the default DBT delete+insert incremental strategy with the new value for incremental_predicates in the arguments dictionary.

How - The below macro implements a light-weight custom incremental strategy do this. You can see at the end it calls the default get_incremental_delete_insert_sql DBT code.

{% macro get_incremental_custom_delete_insert_sql(arg_dict) %}
  {% set custom_arg_dict = arg_dict.copy() %}
  {% set source = custom_arg_dict.get('temp_relation') | string %}
  {% set target = custom_arg_dict.get('target_relation') | string %}

  {% if source is none %}
    {{ exceptions.raise_compiler_error('temp_relation is not present in arguments!') }}
  {% endif %}

  {% if target is none %}
    {{ exceptions.raise_compiler_error('target_relation is not present in arguments!') }}
  {% endif %}

  {% set raw_predicates = custom_arg_dict.get('incremental_predicates', []) %}

  {% if raw_predicates is string %}
    {% set predicates = [raw_predicates]

This is now callable from the DBT model config by setting incremental_strategy to custom_delete_insert.

  - name: model_name
    config:
      materialized: "incremental"
      incremental_strategy: "custom_delete_insert"
      on_schema_change: "append_new_columns"
      unique_key: ["dw_order_created_skey"]
      cluster_by: ["to_date(order_created_at)"]

Performance Improvement Statistics

To find ~100K rows to delete in the target table, now snowflake has to only:

  • Scan ~35 MB of the target table, 11 GB → 35 MB = ~99.68% improvement

  • Scan 12 micro-partitions, 2560 → 12 = ~99.53% improvement

  • Query takes ~1.3 seconds

Less data is being scanned, so the snowflake warehouse is waiting less time on I/O, so the query completes faster.

Query plan


delete query plan


node profile overview

If you're interested in hearing more about how we use DBT at Super Payments, feel free to reach out!

Jag Thind, Data

Copyright 2026 Super Payments. All rights reserved.

Super Payments Limited is a private limited company with company number 13903817. Open banking payments are powered by Yapily Connect Limited and Modulr FS Limited. Yapily Connect Limited is authorised and regulated by the UK Financial Conduct Authority under the Payment Services Regulations 2017 (Firm Reference 827001). Super Payments Limited is a distributor of Modulr FS Limited, a company registered in England and Wales with company number 09897919, which is authorised and regulated by the Financial Conduct Authority as an Electronic Money Institution (Firm Reference Number: 900573) for the issuance of electronic money and payment services. Your business account and related payment services are provided by Modulr FS Limited. Super Payments Information Security Policy is available on request. Whilst Electronic Money products are not covered by the Financial Services Compensation Scheme (FSCS), business funds will be held in one or more segregated accounts and safeguarded in line with the Electronic Money Regulations 2011 - more information. Card payments and business accounts are powered by Stripe Payments UK Limited. Stripe UK Payments Ltd is authorised and regulated by the Financial Conduct Authority (Firm Reference: 900461) as an Electronic Money Institution (Firm Reference Number: 900573) for the issuance of electronic money and payment services.

Super Credit is provided by Abound (see below) and is subject to status. Super is not a lender. Terms apply. Fintern Ltd, trading as Abound, is registered in England & Wales No. 12472034 and is authorised and regulated by the Financial Conduct Authority, FRN 929244. Fintern Ltd, 3rd Floor, 86-90 Paul Street, London, EC2A 4NE. Super Payments Limited, trading as Super and Super Payments, is an Introducer Appointed Representative (FRN 1034245) of Abound and may receive commission for introductions. Missed payments may affect your credit score.

Business address at 123 Buckingham Palace Road, London, SW1W 9SH.

Copyright 2026 Super Payments. All rights reserved.

Super Payments Limited is a private limited company with company number 13903817. Open banking payments are powered by Yapily Connect Limited and Modulr FS Limited. Yapily Connect Limited is authorised and regulated by the UK Financial Conduct Authority under the Payment Services Regulations 2017 (Firm Reference 827001). Super Payments Limited is a distributor of Modulr FS Limited, a company registered in England and Wales with company number 09897919, which is authorised and regulated by the Financial Conduct Authority as an Electronic Money Institution (Firm Reference Number: 900573) for the issuance of electronic money and payment services. Your business account and related payment services are provided by Modulr FS Limited. Super Payments Information Security Policy is available on request. Whilst Electronic Money products are not covered by the Financial Services Compensation Scheme (FSCS), business funds will be held in one or more segregated accounts and safeguarded in line with the Electronic Money Regulations 2011 - more information. Card payments and business accounts are powered by Stripe Payments UK Limited. Stripe UK Payments Ltd is authorised and regulated by the Financial Conduct Authority (Firm Reference: 900461) as an Electronic Money Institution (Firm Reference Number: 900573) for the issuance of electronic money and payment services.

Super Credit is provided by Abound (see below) and is subject to status. Super is not a lender. Terms apply. Fintern Ltd, trading as Abound, is registered in England & Wales No. 12472034 and is authorised and regulated by the Financial Conduct Authority, FRN 929244. Fintern Ltd, 3rd Floor, 86-90 Paul Street, London, EC2A 4NE. Super Payments Limited, trading as Super and Super Payments, is an Introducer Appointed Representative (FRN 1034245) of Abound and may receive commission for introductions. Missed payments may affect your credit score.

Business address at 123 Buckingham Palace Road, London, SW1W 9SH.

Copyright 2026 Super Payments. All rights reserved.

Super Payments Limited is a private limited company with company number 13903817. Open banking payments are powered by Yapily Connect Limited and Modulr FS Limited. Yapily Connect Limited is authorised and regulated by the UK Financial Conduct Authority under the Payment Services Regulations 2017 (Firm Reference 827001). Super Payments Limited is a distributor of Modulr FS Limited, a company registered in England and Wales with company number 09897919, which is authorised and regulated by the Financial Conduct Authority as an Electronic Money Institution (Firm Reference Number: 900573) for the issuance of electronic money and payment services. Your business account and related payment services are provided by Modulr FS Limited. Super Payments Information Security Policy is available on request. Whilst Electronic Money products are not covered by the Financial Services Compensation Scheme (FSCS), business funds will be held in one or more segregated accounts and safeguarded in line with the Electronic Money Regulations 2011 - more information. Card payments and business accounts are powered by Stripe Payments UK Limited. Stripe UK Payments Ltd is authorised and regulated by the Financial Conduct Authority (Firm Reference: 900461) as an Electronic Money Institution (Firm Reference Number: 900573) for the issuance of electronic money and payment services.

Super Credit is provided by Abound (see below) and is subject to status. Super is not a lender. Terms apply. Fintern Ltd, trading as Abound, is registered in England & Wales No. 12472034 and is authorised and regulated by the Financial Conduct Authority, FRN 929244. Fintern Ltd, 3rd Floor, 86-90 Paul Street, London, EC2A 4NE. Super Payments Limited, trading as Super and Super Payments, is an Introducer Appointed Representative (FRN 1034245) of Abound and may receive commission for introductions. Missed payments may affect your credit score.

Business address at 123 Buckingham Palace Road, London, SW1W 9SH.