Skip to content

Commit be6b2de

Browse files
committed
dependent columns were not getting matched because gf.Table is an empty string
1 parent 7607636 commit be6b2de

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

enginetest/queries/query_plans.go

Lines changed: 36 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sql/analyzer/replace_count_star.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func replaceCountStar(ctx *sql.Context, a *Analyzer, n sql.Node, _ *plan.Scope,
6565
rt = t
6666
}
6767
}
68-
if rt == nil {
68+
if rt == nil || sql.IsKeyless(rt.Table.Schema()) {
6969
return n, transform.SameTree, nil
7070
}
7171

sql/analyzer/symbol_resolution.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,15 @@ func pruneTableCols(
208208
}
209209

210210
// Don't prune columns if they're needed by a virtual column
211-
virtualColDeps := make(map[tableCol]int)
211+
virtualColDeps := make(map[string]int)
212212
if !selectStar { // if selectStar, we're adding all columns anyway
213213
if vct, isVCT := n.WrappedTable().(*plan.VirtualColumnTable); isVCT {
214214
for _, projection := range vct.Projections {
215215
transform.InspectExpr(projection, func(e sql.Expression) bool {
216216
if cd, isCD := e.(*sql.ColumnDefaultValue); isCD {
217217
transform.InspectExpr(cd.Expr, func(e sql.Expression) bool {
218218
if gf, ok := e.(*expression.GetField); ok {
219-
c := newTableCol(gf.Table(), gf.Name())
220-
virtualColDeps[c]++
219+
virtualColDeps[gf.Name()]++
221220
}
222221
return false
223222
})
@@ -232,7 +231,7 @@ func pruneTableCols(
232231
source := strings.ToLower(table.Name())
233232
for _, col := range table.Schema() {
234233
c := newTableCol(source, col.Name)
235-
if selectStar || parentCols[c] > 0 || virtualColDeps[c] > 0 {
234+
if selectStar || parentCols[c] > 0 || virtualColDeps[c.Name()] > 0 {
236235
cols = append(cols, c.col)
237236
}
238237
}

0 commit comments

Comments
 (0)