Skip to content

Conversation

@max-hoffman
Copy link
Contributor

The move join condition rule selects filters not needed as a join condition, identify the target parent for the filter, and then moves the plucked filters to EVERY child of the parent of the join node. The correct behavior is to move the filter immediately above the join whose condition we plucked the filter from.

Copy link
Member

@zachmu zachmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

case *plan.Filter:
return false
return transform.NodeWithCtx(node, func(transform.Context) bool { return true }, func(c transform.Context) (sql.Node, transform.TreeIdentity, error) {
if c.Node != topJoin {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this function run recursively up the tree, so each join node gets a turn to be the top node?

I'm curious how this interacts with pushdown, could use some more plan tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will always be one topJoin in a single scope. You would need a subquery, union, etc to get a second scope. If we know the joins are all compact in the tree, we could probably have this whole rule just be a single transform. When we hit a node that isn't a join and the topJoin is not nil we combine the conditions turned where filters. The relationship to pushdown is what you were telling me yesterday: this rule only moves filters from join to where clause, pushdown decides how low filters can be pushed.

@max-hoffman max-hoffman merged commit cdf9f4b into main Sep 2, 2022
@max-hoffman max-hoffman deleted the max/moved-join-conditions-to-filter-bug branch September 2, 2022 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants