-
Notifications
You must be signed in to change notification settings - Fork 592
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
RFC: add logical property Cardinality on PlanNode #2279
Comments
This has to be a runtime error. For example:
This runs happily when t has 0 or 1 rows, but reports an error when it has more. A Could you share more usage examples? I can only think of |
for 1, I had some misunderstanding about that and now notice the error was found in execution after planning in PG. but how can we give this error in execution with just a join planNode and it does not know the subquery? I have another proposal to give an error in frontend when the plan can give more than 1 row. It is a different behavior with PostgreSQL. in other word. we will give a error for for 2, it is for simpleAgg, Limit and TopN. and the is it can derived from input. for example project will not change the |
I just tested it in RW, and it can't report a runtime error for this case, so we need a way to notice backend this limit. As for @st1page 's proposal, I'm neutral. Besides, we can try to derive Cardinality for different operators but I can't see any benefit of Cardinality in other places. |
Not sure if it is useful in other places. so we can change it to an enum like enum logicalCardinality {
zero,
one,
max_one,
multi,
} |
1a] First we need to pick a behavior: runtime error or query rewrite. SQL Server introduced an
(But we still have runtime errors in backend, for example integer overflow.) 1b] In the query rewrite case, encouraging limit-without-order may not be a good idea. An aggregate 2] You are right. I forget limit ... And project or filter can propagate the max. So we only care whether max > 1 for (plan time or runtime) error reporting, and only care whether min >= 1 for unconditional outer join simplification. The latter case seems less useful. The plan above can actually avoid outer join by combining filter above:
Because nulls generated by outer join cannot eval to true for |
think about the optimization, I think it needs constant folding. we can try to improve our filter-join rule. |
so how about just adding the |
My point is:
btw still curious about its usage in cockroachdb |
sure.
As for "LogicalCardinality", "max1row", "min1row", "exact1row" or other similar properties, we can rethink them when we really need them to in optimizing. |
The outer join of q15 has been handled by #2349. |
propose to add a logical property
Cardinality
on the PlanNode like https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/opt/props/cardinality.go. It provides the bound of the rows number returned by the relational operator. It is just the logical bound of the result and not from statistics, which is always correct.how can it be used?
now the scalar subquery needs that.
https://www.postgresql.org/docs/current/sql-expressions.html
the
filter-join
is planned from the scalar subquery, and the outer join's right plan should return less than 1 row. the outer join is for the right input return 0 row(empty set). but in this plan, we know the right input plan, theproj-simpleAgg
must returns 1 row. and we can use inner join but not outer join here, which can be more optimized by push down the predicate.The text was updated successfully, but these errors were encountered: