Skip to content

Commit

Permalink
Fix materialized_views filters when listing relations
Browse files Browse the repository at this point in the history
Before the change, the `list_relations_without_caching` macro queried
`system.metadata.materialized_views` with no effective filter on the
catalog and schema name. In theory the Trino optimizer could figure out
the effective predicate on the `system.metadata.materialized_views`
table, but in practice it was not happening, and all materialized views
from all catalogs where being pulled.
  • Loading branch information
findepi committed Sep 27, 2023
1 parent ff99ddc commit 0589040
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions dbt/include/trino/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@
else t.table_type
end as table_type
from {{ relation.information_schema() }}.tables t
left join system.metadata.materialized_views mv
left join (
SELECT *
FROM system.metadata.materialized_views
WHERE catalog_name = '{{ relation.database | lower }}'
AND schema_name = '{{ relation.schema | lower }}') mv
on mv.catalog_name = t.table_catalog and mv.schema_name = t.table_schema and mv.name = t.table_name
where t.table_schema = '{{ relation.schema | lower }}'
and (mv.catalog_name is null or mv.catalog_name = '{{ relation.database | lower }}')
and (mv.schema_name is null or mv.schema_name = '{{ relation.schema | lower }}')
{% endcall %}
{{ return(load_result('list_relations_without_caching').table) }}
{% endmacro %}
Expand Down

0 comments on commit 0589040

Please sign in to comment.