Skip to content

Commit

Permalink
Avoid nested loop in query planner execution (#612)
Browse files Browse the repository at this point in the history
* Adjust not equals application order

  - Move relation name not equals from outer SELECT `where` clause
    to dependency CTE
      - Seems to more reliably push query planner to avoid a nested
        loop
      - Should preserve original intent, i.e. to exclude
        self-references from final result
      - Execution plan suggests this reduces the row estimate for
        the outer SELECT
      - Real-world testing on internal company cluster under
        conditions where nested loop is used for original, shows
	that the new approach continues to perform and behave as
	expected (no nested loop)

* Add changie entry
  • Loading branch information
slin30 authored Sep 25, 2023
1 parent 08625fe commit 9385b49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Fixes-20230923-091155.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Fixes
body: avoid nested loop in query planner execution of redshift__get_relations
time: 2023-09-23T09:11:55.2152725-04:00
custom:
Author: slin30
Issue: "609"
2 changes: 1 addition & 1 deletion dbt/include/redshift/macros/relations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ with
from pg_depend
left join pg_rewrite
on pg_depend.objid = pg_rewrite.oid
where coalesce(pg_rewrite.ev_class, pg_depend.objid) != pg_depend.refobjid
)

select distinct
Expand All @@ -36,7 +37,6 @@ join relation ref
on dependency.ref_relation_id = ref.relation_id
join relation dep
on dependency.dep_relation_id = dep.relation_id
where ref.relation_name != dep.relation_name

{%- endcall -%}

Expand Down

0 comments on commit 9385b49

Please sign in to comment.