# Enable query optimizer hotfixes in dbt model

**URL:** <https://discourse.getdbt.com/t/enable-query-optimizer-hotfixes-in-dbt-model/20073>\
**Category:** Help\
**Tags:** incremental\
**Created:** [August 11, 2025, 1:29pm UTC](https://discourse.getdbt.com/t/enable-query-optimizer-hotfixes-in-dbt-model/20073 "2025-08-11T13:29:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tea](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@tea](https://discourse.getdbt.com/u/tea)\
**Post date:** [August 11, 2025, 1:29pm UTC](https://discourse.getdbt.com/t/enable-query-optimizer-hotfixes-in-dbt-model/20073/1 "2025-08-11T13:29:06Z")

</div>

## The problem I’m having

I am trying to migrate code from at stored procedure in T-SQL to an incremental dbt model.

In the stored procedure, we are using

OPTION (USE HINT (‘ENABLE\_QUERY\_OPTIMIZER\_HOTFIXES’))

in order to achieve good performance.

It seems I cannot include this code line in the dbt -model - it fails with error message “Encountered unknown tag ‘OPTION’.”.

Is there a way to solve this? Some macro that allows me to enable the query optimizer hotfixes, or some other workaround?

## The context of why I’m trying to do this

We have a SQL Server database, and we use Polybase to connect to our source data, which are located in an Oracle database, through external tables.

Without the query optimizer hotfixes enabled, we get problems with the performance because the filter clause, i.e.

where date\_day \>= (select coalesce(max(date\_day), ‘1900-01-01’) from {{ this }})

is not pushed down to the source database.

## What I’ve already tried

I have tried to omit the ENABLE\_QUERY\_OPTIMIZER\_HOTFIXES, to see if dbt somehow handles this in some other smart way. But the result is that the performance for an incremental load is like the performance for a full refresh of the model.

---

<div class="post-metadata">

**Author:** ![tea](https://avatars.discourse-cdn.com/v4/letter/t/7ea924/32.png) [@tea](https://discourse.getdbt.com/u/tea)\
**Post date:** [August 13, 2025, 6:03am UTC](https://discourse.getdbt.com/t/enable-query-optimizer-hotfixes-in-dbt-model/20073/2 "2025-08-13T06:03:44Z")

</div>

I found a solution where I do not need the query optimizer hotfix enabled. I used a macro to calculate the max(date\_day), and then I assigned the max date to a jinja variable max\_date\_day using this macro in a set operation. Then my filter clause for incremental load would get a fixed date in the compiled sql, not a variable:

Instead of this:

where date\_day \>= (select coalesce(max(date\_day), ‘1900-01-01’) from {{ this }})

I now have this:  
{% if is\_incremental() %}  
where date\_day \> ‘{{max\_date\_day}}’  
{% endif %}

Which compiles to something like this in an incremental load:  
where date\_day \> ‘2025-08-13 07:33:29’

And since the problem with pushdown for Polybase occurs when there is a variable in the filter clause, I no longer have this problem.
