Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: introduce helper method to extract logic #15939

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions go/vt/sqlparser/ast_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,14 @@ func (node *Select) AddGroupBy(expr Expr) {
node.GroupBy.Exprs = append(node.GroupBy.Exprs, expr)
}

// GroupByExprs returns the group by expressions
func (node *Select) GroupByExprs() []Expr {
if node.GroupBy == nil {
return nil
}
return node.GroupBy.Exprs
}

// AddWhere adds the boolean expression to the
// WHERE clause as an AND condition.
func (node *Update) AddWhere(expr Expr) {
Expand Down
22 changes: 10 additions & 12 deletions go/vt/vtgate/semantics/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,17 @@ func (b *binder) searchInSelectExpressions(colName *sqlparser.ColName, deps depe
return dependency{certain: true, direct: direct, recursive: recursive, typ: typ}
}
}
if stmt.GroupBy != nil {
for _, gb := range stmt.GroupBy.Exprs {
selectCol, ok := gb.(*sqlparser.ColName)
if !ok || !selectCol.Name.Equal(colName.Name) {
continue
}
for _, gb := range stmt.GroupByExprs() {
selectCol, ok := gb.(*sqlparser.ColName)
if !ok || !selectCol.Name.Equal(colName.Name) {
continue
}

_, direct, _ := b.org.depsForExpr(selectCol)
if deps.direct == direct {
// we have found the ColName in the GROUP BY expressions, so it's safe to use here
direct, recursive, typ := b.org.depsForExpr(gb)
return dependency{certain: true, direct: direct, recursive: recursive, typ: typ}
}
_, direct, _ := b.org.depsForExpr(selectCol)
if deps.direct == direct {
// we have found the ColName in the GROUP BY expressions, so it's safe to use here
direct, recursive, typ := b.org.depsForExpr(gb)
return dependency{certain: true, direct: direct, recursive: recursive, typ: typ}
}
}
return dependency{}
Expand Down
Loading