From 56b14592419ea73dc81fcb94b96df9d4ae9d2aac Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Tue, 3 Oct 2023 16:11:52 +0200 Subject: [PATCH] Query table_comments without unrolling with UNION ALL `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. --- .changes/unreleased/Under the Hood-20231003-161428.yaml | 7 +++++++ dbt/include/trino/macros/catalog.sql | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 .changes/unreleased/Under the Hood-20231003-161428.yaml diff --git a/.changes/unreleased/Under the Hood-20231003-161428.yaml b/.changes/unreleased/Under the Hood-20231003-161428.yaml new file mode 100644 index 00000000..18c8413b --- /dev/null +++ b/.changes/unreleased/Under the Hood-20231003-161428.yaml @@ -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" diff --git a/dbt/include/trino/macros/catalog.sql b/dbt/include/trino/macros/catalog.sql index d7e252c3..f7c63283 100644 --- a/dbt/include/trino/macros/catalog.sql +++ b/dbt/include/trino/macros/catalog.sql @@ -67,7 +67,6 @@ {% macro trino__get_catalog_table_comment_schemas_sql(information_schema, schemas) -%} - {%- for schema in schemas %} select catalog_name as "table_database", schema_name as "table_schema", @@ -79,11 +78,7 @@ and schema_name != 'information_schema' and - schema_name = '{{ schema | lower }}' - {%- if not loop.last %} - union all - {% endif -%} - {%- endfor -%} + schema_name in ('{{ schemas | join("','") | lower }}') {%- endmacro %}