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

core: fix subQuery at projection in only_full_group #22416

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
14 changes: 13 additions & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3129,7 +3129,7 @@
if field.Auxiliary {
continue
}
checkExprInGroupByOrIsSingleValue(p, getInnerFromParenthesesAndUnaryPlus(field.Expr), offset, ErrExprInSelect, gbyOrSingleValueColNames, gbyExprs, notInGbyOrSingleValueColNames)
checkExprInGroupByOrIsSingleValue(p, getInnerExpr(field.Expr), offset, ErrExprInSelect, gbyOrSingleValueColNames, gbyExprs, notInGbyOrSingleValueColNames)
}

if sel.OrderBy != nil {
Expand Down Expand Up @@ -6570,6 +6570,18 @@
})
}

func getInnerExpr(expr ast.ExprNode) ast.ExprNode {
expr = getInnerFromParenthesesAndUnaryPlus(expr)

if sqpr, ok := expr.(*ast.SubqueryExpr); ok && sqpr.Query != nil {
if selSt, ok := sqpr.Query.(*ast.SelectStmt); ok && selSt.From == nil &&
len(selSt.Fields.Fields) > 0 {
return getInnerExpr(selSt.Fields.Fields[0].Expr)
}

Check warning on line 6580 in planner/core/logical_plan_builder.go

View check run for this annotation

Codecov / codecov/patch

planner/core/logical_plan_builder.go#L6579-L6580

Added lines #L6579 - L6580 were not covered by tests
}
return expr
}

func getInnerFromParenthesesAndUnaryPlus(expr ast.ExprNode) ast.ExprNode {
if pexpr, ok := expr.(*ast.ParenthesesExpr); ok {
return getInnerFromParenthesesAndUnaryPlus(pexpr.Expr)
Expand Down