Skip to content
Merged
Changes from 1 commit
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
Next Next commit
fix(compiler): Fix to not scan children under ast.RangeSubselect when…
… retrieving table listing

close #2569
  • Loading branch information
orisano committed Aug 3, 2023
commit 15e850cabcb0053c1cabb02a963ffba9fbc850ee
28 changes: 20 additions & 8 deletions internal/compiler/output_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,23 @@ func isTableRequired(n ast.Node, col *Column, prior int) int {
return tableNotFound
}

type tableVisitor struct {
list ast.List
}

func (r *tableVisitor) Visit(n ast.Node) astutils.Visitor {
switch n.(type) {
case *ast.RangeVar, *ast.RangeFunction:
r.list.Items = append(r.list.Items, n)
return r
case *ast.RangeSubselect:
r.list.Items = append(r.list.Items, n)
return nil
default:
return r
}
}

// Compute the output columns for a statement.
//
// Return an error if column references are ambiguous
Expand All @@ -470,14 +487,9 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
Items: []ast.Node{n.Relation},
}
case *ast.SelectStmt:
list = astutils.Search(n.FromClause, func(node ast.Node) bool {
switch node.(type) {
case *ast.RangeVar, *ast.RangeSubselect, *ast.RangeFunction:
return true
default:
return false
}
})
var tv tableVisitor
astutils.Walk(&tv, n.FromClause)
list = &tv.list
case *ast.TruncateStmt:
list = astutils.Search(n.Relations, func(node ast.Node) bool {
_, ok := node.(*ast.RangeVar)
Expand Down