Uh oh!
There was an error while loading. Please reload this page.
Detect when filters on unique constraints make subqueries scalar - #8312
Conversation
2f4cb79 to
44383c2Comparealamb
commented
Nov 27, 2023
Thank you @Jesse-Bakker -- I plan to review this carefully tomorrow |
alamb
left a comment
There was a problem hiding this comment.
Thank you @Jesse-Bakker -- this looks great. I had a few suggestions, mostly about comments, and code reuse. But otherwise I think this PR is pretty much ready
cc @liukun4515 and @jackwener who may have some more thoughts about subquery rewrites
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
alamb
commented
Nov 28, 2023
The only thing I think is strictly needed to approve this PR is docstrings for "is_scalar" -- the rest is "nice to have" from my perspective / could be done as a follow on PR |
52fadb7 to
f33a843Compare
I will review this PR and think more about it. If this PR isn't urgent, please wait for me. |
f33a843 to
16db847Compare| /// `Filter(b = 2).is_scalar() == false` | ||
| /// and | ||
| /// `Filter(a = 2 OR b = 2).is_scalar() == false` | ||
| fn is_scalar(&self) -> bool { |
There was a problem hiding this comment.
I suggest use Uniform slot and Unique slot to describe FDs instead of scalar.
Commonly used Functional dependencies : including
uniform slot, which means ndv <= 1unique slot, which means ndv = row
There was a problem hiding this comment.
Do I understand correctly that the suggestion is to rename this method to Filter::is_uniform()?
There was a problem hiding this comment.
Yes, and add these definition into doc/
Uh oh!
There was an error while loading. Please reload this page.
alamb
left a comment
There was a problem hiding this comment.
Thank you @Jesse-Bakker - let's see if @jackwener has a chance to clarify. If we haven't heard by tomorrow I'll merge this PR
Uh oh!
There was an error while loading. Please reload this page.
jackwener
left a comment
There was a problem hiding this comment.
Thanks @Jesse-Bakker@alamb
I have no other question.
alamb
commented
Dec 6, 2023
I took the liberty of merging up from main to resolve a conflict in this PR |
alamb
commented
Dec 6, 2023
Thanks again @Jesse-Bakker and @jackwener |
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Which issue does this PR close?
Part of #3725
Rationale for this change
In some cases, it is possible to prove that a Filter only ever produces one
row. In those cases, such a filter may be used in a scalar subquery to ensure
it is in fact scalar, allowing for more flexible use of scalar subqueries.
What changes are included in this PR?
This adds an
is_scalar()method toFilter, which will check if there is aunique functional dependence which is covered by the
Filter's predicate.This is used in
LogicalPlan::max_rows()to provide a tighter bound on themaximum number of rows returned in the presence of
Filters.Are these changes tested?
This is directly tested with a unit test and with a
sqllogictestthat exercisesthe more flexible use of scalar subqueries.
Are there any user-facing changes?
Scalar subqueries are more flexible. Previous constraints were not documented
as far as I can tell