Skip to content

Commit

Permalink
Speedup catalog string comparison by using ilike before equals
Browse files Browse the repository at this point in the history
  • Loading branch information
aranke committed Apr 22, 2024
1 parent f2f0868 commit c8cf190
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions dbt/include/snowflake/macros/catalog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,14 @@
{%- endmacro %}


{% macro snowflake__catalog_equals(field, value) %}
"{{ field }}" ilike '{{ value }}' and upper("{{ field }}") = upper('{{ value }}')
{% endmacro %}


{% macro snowflake__get_catalog_schemas_where_clause_sql(schemas) -%}
where ({%- for schema in schemas -%}
upper("table_schema") = upper('{{ schema }}'){%- if not loop.last %} or {% endif -%}
{{ snowflake__catalog_equals('table_schema', schema) }}{%- if not loop.last %} or {% endif -%}
{%- endfor -%})
{%- endmacro %}

Expand All @@ -107,12 +112,12 @@
{%- for relation in relations -%}
{% if relation.schema and relation.identifier %}
(
upper("table_schema") = upper('{{ relation.schema }}')
and upper("table_name") = upper('{{ relation.identifier }}')
{{ snowflake__catalog_equals('table_schema', relation.schema) }}
and {{ snowflake__catalog_equals('table_name', relation.identifier) }}
)
{% elif relation.schema %}
(
upper("table_schema") = upper('{{ relation.schema }}')
{{ snowflake__catalog_equals('table_schema', relation.schema) }}
)
{% else %}
{% do exceptions.raise_compiler_error(
Expand Down

0 comments on commit c8cf190

Please sign in to comment.