graphile / graphile/crystal

Optimization: detect when inlining is equivalent to a relational join (and replace it)

Open
#2,595 0 comments 0 reactions 0 assignees View on GitHub
✨ feature
Dominant language
TypeScript
Stars
12.9k
Forks
625
Avg merge
5h 23m
Merged PRs (30d)
24

Description

Currently relations are expressed via new PgSelect and then at optimize the join can be made (this allows you to forbid joining if you want).

However, when we want to order/condition on a relational poly table (see #2593) we also want to do a relational join.

Currently we can't tell that these are equivalent, and it results in two separate joins. Would be better if we could detect that the join would be equivalent to a relational join and do that instead during optimize - then we can use that relational join in other places without duplication.

```diff
select
__relational_topics__."topic_item_id"::text as "0",
- __relational_items__."id"::text as "1"
+ __relational_items_by_my_topic_item_id__."id"::text as "1"
from "polymorphic"."relational_topics" as __relational_topics__
left outer join "polymorphic"."relational_items" as __relational_items_by_my_topic_item_id__
on (__relational_topics__."topic_item_id" = __relational_items_by_my_topic_item_id__."id")
-left outer join "polymorphic"."relational_items" as __relational_items__
-on (
-/* WHERE becoming ON */ (
- __relational_items__."id" = __relational_topics__."topic_item_id"
-))
where (
__relational_items_by_my_topic_item_id__."archived_at" is null
)
order by __relational_items_by_my_topic_item_id__."created_at" asc, __relational_topics__."topic_item_id" asc;
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.