Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal committed Jun 5, 2024
1 parent 4d23f76 commit 5036a2f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
7 changes: 3 additions & 4 deletions go/vt/vtgate/planbuilder/operators/aggregation_pushing.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ func pushAggregationThroughSubquery(
}
pushedAggr.addColumnWithoutPushing(ctx, aeWrap(colName), true)
}
for _, aggregation := range pushedAggr.Aggregations {
aggregation.Original.Expr = subQuery.rewriteColNameToArgument(aggregation.Original.Expr)
}
}

src.Outer = pushedAggr

for _, aggregation := range pushedAggr.Aggregations {
aggregation.Original.Expr = rewriteColNameToArgument(ctx, aggregation.Original.Expr, aggregation.SubQueryExpression, src.Inner...)
}

if !rootAggr.Original {
return src, Rewrote("push Aggregation under subquery - keep original")
}
Expand Down
10 changes: 5 additions & 5 deletions go/vt/vtgate/planbuilder/operators/subquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

// SubQuery represents a subquery used for filtering rows in an
// outer query through a join.
type /**/ SubQuery struct {
type SubQuery struct {
// Fields filled in at the time of construction:
Outer Operator // Outer query operator.
Subquery Operator // Subquery operator.
Expand All @@ -53,7 +53,7 @@ type /**/ SubQuery struct {
// We use this information to fail the planning if we are unable to merge the subquery with a route.
correlated bool

IsProjection bool
IsArgument bool
}

func (sq *SubQuery) planOffsets(ctx *plancontext.PlanningContext) Operator {
Expand Down Expand Up @@ -156,8 +156,8 @@ func (sq *SubQuery) SetInputs(inputs []Operator) {

func (sq *SubQuery) ShortDescription() string {
var typ string
if sq.IsProjection {
typ = "PROJ"
if sq.IsArgument {
typ = "ARG"
} else {
typ = "FILTER"
}
Expand Down Expand Up @@ -210,7 +210,7 @@ func (sq *SubQuery) settle(ctx *plancontext.PlanningContext, outer Operator) Ope
if sq.correlated && sq.FilterType != opcode.PulloutExists {
panic(correlatedSubqueryErr)
}
if sq.IsProjection {
if sq.IsArgument {
if len(sq.GetMergePredicates()) > 0 {
// this means that we have a correlated subquery on our hands
panic(correlatedSubqueryErr)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/subquery_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func createSubquery(
Original: original,
ArgName: argName,
originalSubquery: originalSq,
IsProjection: isProjection,
IsArgument: isProjection,
TopLevel: topLevel,
JoinColumns: joinCols,
correlated: correlated,
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vtgate/planbuilder/operators/subquery_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func tryMergeSubqueryWithOuter(ctx *plancontext.PlanningContext, subQuery *SubQu
if op == nil {
return outer, NoRewrite
}
if !subQuery.IsProjection {
if !subQuery.IsArgument {
op.Source = newFilter(outer.Source, subQuery.Original)
}
ctx.MergedSubqueries = append(ctx.MergedSubqueries, subQuery.originalSubquery)
Expand Down Expand Up @@ -582,7 +582,7 @@ func (s *subqueryRouteMerger) merge(ctx *plancontext.PlanningContext, inner, out
var src Operator
if isSharded {
src = s.outer.Source
if !s.subq.IsProjection {
if !s.subq.IsArgument {
src = newFilter(s.outer.Source, s.original)
}
} else {
Expand Down Expand Up @@ -643,7 +643,7 @@ func (s *subqueryRouteMerger) rewriteASTExpression(ctx *plancontext.PlanningCont
panic(err)
}

if s.subq.IsProjection {
if s.subq.IsArgument {
ctx.SemTable.CopySemanticInfo(s.subq.originalSubquery.Select, subqStmt)
s.subq.originalSubquery.Select = subqStmt
} else {
Expand Down

0 comments on commit 5036a2f

Please sign in to comment.