dialect/sql: reduce the number of joins on neighbors without predicates (#154)

Summary:
Pull Request resolved: https://github.com/facebookincubator/ent/pull/154

Loading the "form" table is not required where there's no predicate on the join.

Reviewed By: alexsn

Differential Revision: D18421062

fbshipit-source-id: cb2a045a5a8a76ea4f07e5cf4305a6da338a616e
This commit is contained in:
Ariel Mashraki
2019-11-10 21:50:18 -08:00
committed by Facebook Github Bot
parent 514c0ff6d3
commit 73e294a21e
2 changed files with 36 additions and 4 deletions

View File

@@ -78,13 +78,10 @@ func Neighbors(dialect string, s *Step) (q *Selector) {
pk1, pk2 = pk2, pk1
}
to := builder.Table(s.To.Table)
from := builder.Table(s.From.Table)
join := builder.Table(s.Edge.Table)
match := builder.Select(join.C(pk1)).
From(join).
Join(from).
On(join.C(pk2), from.C(s.From.Column)).
Where(EQ(from.C(s.From.Column), s.From.V))
Where(EQ(join.C(pk2), s.From.V))
q = builder.Select().
From(to).
Join(match).