diff --git a/.changes/unreleased/Under the Hood-20240425-144556.yaml b/.changes/unreleased/Under the Hood-20240425-144556.yaml new file mode 100644 index 000000000..002da3c1f --- /dev/null +++ b/.changes/unreleased/Under the Hood-20240425-144556.yaml @@ -0,0 +1,6 @@ +kind: Under the Hood +body: Speedup catalog string comparison by using ilike before equals +time: 2024-04-25T14:45:56.549787+02:00 +custom: + Author: aranke + Issue: '1035' diff --git a/dbt/include/snowflake/macros/catalog.sql b/dbt/include/snowflake/macros/catalog.sql index 8354d3c44..bde8b8f8f 100644 --- a/dbt/include/snowflake/macros/catalog.sql +++ b/dbt/include/snowflake/macros/catalog.sql @@ -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 %} @@ -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(