Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions enginetest/queries/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -9181,6 +9181,11 @@ from typestable`,
Query: "select pk, (select max(pk) from one_pk where pk < opk.pk) as x from one_pk opk",
Expected: []sql.Row{{0, nil}, {1, 0}, {2, 1}, {3, 2}},
},
{
// https://github.com/dolthub/dolt/issues/9963
Query: "select max(i) as max_i from mytable having max(i) < 3",
Expected: []sql.Row{},
},
}

var KeylessQueries = []QueryTest{
Expand Down
6 changes: 3 additions & 3 deletions enginetest/queries/tpcc_plans.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions enginetest/queries/tpch_plans.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions sql/analyzer/validation_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,13 @@ func validateGroupBy(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scop
}

var err error
var parent sql.Node
var project *plan.Project
var orderBy *plan.Sort
transform.Inspect(n, func(n sql.Node) bool {
defer func() {
parent = n
}()
switch n := n.(type) {
case *plan.GroupBy:
var noGroupBy bool
Expand Down Expand Up @@ -334,8 +338,10 @@ func validateGroupBy(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.Scop
}
}
case *plan.Project:
project = n
orderBy = nil
if _, isHaving := parent.(*plan.Having); !isHaving {
project = n
orderBy = nil
}
case *plan.Sort:
orderBy = n
}
Expand Down Expand Up @@ -406,6 +412,7 @@ func resolveExpr(expr sql.Expression, selectDeps map[string]sql.Expression, grou
switch expr := expr.(type) {
case *expression.Alias:
if dep, ok := selectDeps[strings.ToLower(expr.Child.String())]; ok {
selectDeps[strings.ToLower(expr.Name())] = dep
return dep, transform.NewTree, nil
}
case *expression.GetField:
Expand Down
1 change: 0 additions & 1 deletion sql/planbuilder/aggregates.go
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,6 @@ func (b *Builder) analyzeHaving(fromScope, projScope *scope, having *ast.Where)
// record aggregate
// TODO: this should get projScope as well
_ = b.buildAggregateFunc(fromScope, name, n)
return false, nil
} else if isWindowFunc(name) {
_ = b.buildWindowFunc(fromScope, name, n, (*ast.WindowDef)(n.Over))
}
Expand Down
18 changes: 9 additions & 9 deletions sql/planbuilder/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ Project
│ ├─ avg(cte.x):5
│ └─ 0 (tinyint)
└─ Project
├─ columns: [avg(cte.x):5, 1 (tinyint)->x:4]
├─ columns: [avg(cte.x):5, cte.x:3!null, 1 (tinyint)->x:4]
└─ GroupBy
├─ select: AVG(cte.x:3!null)
├─ select: AVG(cte.x:3!null), cte.x:3!null
├─ group:
└─ SubqueryAlias
├─ name: cte
Expand Down Expand Up @@ -260,9 +260,9 @@ Project
│ ├─ avg(xy.x):5
│ └─ 0 (tinyint)
└─ Project
├─ columns: [avg(xy.x):5, 1 (tinyint)->x:4]
├─ columns: [avg(xy.x):5, xy.x:1!null, 1 (tinyint)->x:4]
└─ GroupBy
├─ select: AVG(xy.x:1!null)
├─ select: AVG(xy.x:1!null), xy.x:1!null
├─ group:
└─ Table
├─ name: xy
Expand Down Expand Up @@ -1029,7 +1029,7 @@ Project
│ ├─ sum((xy.y * xy.z)):4!null
│ └─ 1 (tinyint)
└─ GroupBy
├─ select: SUM((xy.y:2!null * xy.z:3!null)), xy.x:1!null
├─ select: SUM((xy.y:2!null * xy.z:3!null)), xy.x:1!null, xy.y:2!null, xy.z:3!null
├─ group: xy.x:1!null
└─ Table
├─ name: xy
Expand Down Expand Up @@ -1691,9 +1691,9 @@ Project
│ │ ├─ count(uv.u):7!null
│ │ └─ 1 (bigint)
│ └─ Project
│ ├─ columns: [count(uv.u):7!null, count(uv.u):7!null->count_1:8]
│ ├─ columns: [count(uv.u):7!null, uv.u:4!null, count(uv.u):7!null->count_1:8]
│ └─ GroupBy
│ ├─ select: COUNT(uv.u:4!null)
│ ├─ select: COUNT(uv.u:4!null), uv.u:4!null
│ ├─ group: uv.u:4!null
│ └─ Filter
│ ├─ Eq
Expand Down Expand Up @@ -2156,9 +2156,9 @@ Project
├─ NOT
│ └─ avg(-xy.y):5 IS NULL
└─ Project
├─ columns: [avg(-xy.y):5, xy.x:1!null, xy.x:1!null->y:4]
├─ columns: [avg(-xy.y):5, xy.x:1!null, xy.y:2!null, xy.x:1!null->y:4]
└─ GroupBy
├─ select: AVG(-xy.y), xy.x:1!null
├─ select: AVG(-xy.y), xy.x:1!null, xy.y:2!null
├─ group: xy.x:1!null
└─ Table
├─ name: xy
Expand Down