Skip to content

Commit 87ed65e

Browse files
committed
comments clean up
1 parent 66798a4 commit 87ed65e

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

enginetest/queries/queries.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11456,10 +11456,10 @@ var BrokenErrorQueries = []QueryErrorTest{
1145611456
ExpectedErr: sql.ErrTableNotFound,
1145711457
},
1145811458

11459-
// Our behavior in when sql_mode = ONLY_FULL_GROUP_BY is inconsistent with MySQL
11459+
// Our behavior in when sql_mode = ONLY_FULL_GROUP_BY is inconsistent with MySQL. This is because we skip validation
11460+
// for GroupBys wrapped in a Project since we are not able to validate selected expressions that get optimized as an
11461+
// alias.
1146011462
// Relevant issue: https://github.com/dolthub/dolt/issues/4998
11461-
// Special case: If you are grouping by every field of the PK, then you can select anything
11462-
// Otherwise, whatever you are selecting must be in the Group By (with the exception of aggregations)
1146311463
{
1146411464
Query: "SELECT col0, floor(col1) FROM tab1 GROUP by col0;",
1146511465
ExpectedErr: analyzererrors.ErrValidationGroupBy,

sql/analyzer/validation_rules.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ func validateGroupBy(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scop
264264
case *plan.Having, *plan.Project, *plan.Sort:
265265
// TODO: these shouldn't be skipped but we currently aren't able to validate GroupBys with selected aliased
266266
// expressions and a lot of our tests group by aliases
267+
// https://github.com/dolthub/dolt/issues/4998
267268
return true
268269
}
269270

@@ -297,6 +298,8 @@ func validateGroupBy(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scop
297298

298299
for _, expr := range gb.SelectedExprs {
299300
if !expressionReferencesOnlyGroupBys(groupBys, expr) {
301+
// TODO: this is currently too restrictive. Dependent columns are fine to reference
302+
// https://dev.mysql.com/doc/refman/8.4/en/group-by-functional-dependence.html
300303
err = analyzererrors.ErrValidationGroupBy.New(expr.String())
301304
return false
302305
}
@@ -310,12 +313,11 @@ func validateGroupBy(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scop
310313
func expressionReferencesOnlyGroupBys(groupBys map[string]bool, expr sql.Expression) bool {
311314
valid := true
312315
sql.Inspect(expr, func(expr sql.Expression) bool {
313-
exprStr := strings.ToLower(expr.String())
314316
switch expr := expr.(type) {
315317
case nil, sql.Aggregation, *expression.Literal:
316318
return false
317319
default:
318-
if groupBys[exprStr] {
320+
if groupBys[strings.ToLower(expr.String())] {
319321
return false
320322
}
321323

0 commit comments

Comments
 (0)