Skip to content

Commit ca2a237

Browse files
committed
don't prune VirtualColumnTable tables
1 parent be6b2de commit ca2a237

File tree

1 file changed

+8
-21
lines changed

1 file changed

+8
-21
lines changed

sql/analyzer/symbol_resolution.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -202,36 +202,23 @@ func pruneTableCols(
202202
return n, transform.SameTree, nil
203203
}
204204

205+
// columns don't need to be pruned if there's a star
205206
_, selectStar := parentStars[table.Name()]
206-
if unqualifiedStar {
207-
selectStar = true
207+
if selectStar || unqualifiedStar {
208+
return n, transform.SameTree, nil
208209
}
209210

210-
// Don't prune columns if they're needed by a virtual column
211-
virtualColDeps := make(map[string]int)
212-
if !selectStar { // if selectStar, we're adding all columns anyway
213-
if vct, isVCT := n.WrappedTable().(*plan.VirtualColumnTable); isVCT {
214-
for _, projection := range vct.Projections {
215-
transform.InspectExpr(projection, func(e sql.Expression) bool {
216-
if cd, isCD := e.(*sql.ColumnDefaultValue); isCD {
217-
transform.InspectExpr(cd.Expr, func(e sql.Expression) bool {
218-
if gf, ok := e.(*expression.GetField); ok {
219-
virtualColDeps[gf.Name()]++
220-
}
221-
return false
222-
})
223-
}
224-
return false
225-
})
226-
}
227-
}
211+
// pruning VirtualColumnTable underlying tables causes indexing errors when VirtualColumnTable.Projections (which are sql.Expression)
212+
// are evaluated
213+
if _, isVCT := n.WrappedTable().(*plan.VirtualColumnTable); isVCT {
214+
return n, transform.SameTree, nil
228215
}
229216

230217
cols := make([]string, 0)
231218
source := strings.ToLower(table.Name())
232219
for _, col := range table.Schema() {
233220
c := newTableCol(source, col.Name)
234-
if selectStar || parentCols[c] > 0 || virtualColDeps[c.Name()] > 0 {
221+
if parentCols[c] > 0 {
235222
cols = append(cols, c.col)
236223
}
237224
}

0 commit comments

Comments
 (0)