diff --git a/internal/db/postgres/subset/graph.go b/internal/db/postgres/subset/graph.go index 468e511f..5957b9c6 100644 --- a/internal/db/postgres/subset/graph.go +++ b/internal/db/postgres/subset/graph.go @@ -874,7 +874,12 @@ func generateInClauseForOverlap(scopeId int, edges []*Edge, overlap [][]*Edge) s rightTableKeys, leftTableKeys []string ) - for _, c := range overlap { + var shiftedOverlaps [][]*Edge + for _, oc := range overlap { + shiftedOverlaps = append(shiftedOverlaps, shiftUntilVertexWillBeFirst(edges[0], oc)) + } + + for _, c := range shiftedOverlaps { overlapTables = append(overlapTables, getCycleQueryName(scopeId, c, "")) } for _, k := range edges[0].from.table.PrimaryKey { @@ -1068,3 +1073,15 @@ func shiftCycleGroup(g [][]*Edge) [][]*Edge { } return g } + +func shiftUntilVertexWillBeFirst(v *Edge, c []*Edge) []*Edge { + //generateInClauseForOverlap + res := slices.Clone(c) + for { + if res[0].from.idx == v.from.idx { + break + } + res = shiftCycle(res) + } + return res +}