Skip to content

Commit

Permalink
Query table_comments without unrolling with UNION ALL
Browse files Browse the repository at this point in the history
`table_comments` is equally "hard" for the engine as
`information_schema.columns`. Avoid optimizing the query on the `dbt`
side by sending `UNION ALL` with individual schemas. Let the engine
figure out the optimal strategy.
  • Loading branch information
findepi committed Oct 3, 2023
1 parent 6d4cc2a commit 8029d67
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20231003-161428.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Under the Hood
body: Query table_comments without unrolling with UNION ALL
time: 2023-10-03T16:14:28.238801+02:00
custom:
Author: findepi
Issue: ""
PR: "357"
9 changes: 2 additions & 7 deletions dbt/include/trino/macros/catalog.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,11 @@
where
table_schema != 'information_schema'
and
table_schema in ('{{ schemas | join("','") | lower }}')
schema_name in ('{{ schemas | join("','") | lower }}')

),

table_comment as (
{%- for schema in schemas %}
select
catalog_name as "table_database",
schema_name as "table_schema",
Expand All @@ -51,11 +50,7 @@
and
schema_name != 'information_schema'
and
schema_name = '{{ schema | lower }}'
{% if not loop.last %}
union all
{% endif %}
{%- endfor %}
table_schema in ('{{ schemas | join("','") | lower }}')
)

select
Expand Down

0 comments on commit 8029d67

Please sign in to comment.