Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix for pushing a projection down to a table in a subquery more than once #282

Merged
merged 2 commits into from
Feb 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion sql/analyzer/pushdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,21 @@ func canProject(n sql.Node, a *Analyzer) bool {
return false
}

return true
// Because analysis runs more than once on subquery, it's possible for projection pushdown logic to be applied
// multiple times. It's totally undefined what happens when you push a projection down to a table that already has
// one, and shouldn't happen. We don't have the necessary interface to interrogate a projected table about its
// projection, so we do this for now.
// TODO: this is a hack, we shouldn't use decorator nodes for logic like this.
alreadyPushedDown := false
plan.Inspect(n, func(n sql.Node) bool {
if n, ok := n.(*plan.DecoratedNode); ok && strings.Contains(n.String(), "Projected table access on") {
alreadyPushedDown = true
return false
}
return true
})

return !alreadyPushedDown
}

// canDoPushdown returns whether the node given can safely be analyzed for pushdown
Expand Down