You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Replace Filter: Boolean(false) with EmptyRelation #3864
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
I have a query that looks like this after optimization:
Describe the solution you'd like
Remove everything under the Filter that is always false and replace with EmptyRelation so that we avoid executing the join and aggregate.
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
Additional context
Add any other context or screenshots about the feature request here.
We can have two general rules: FoldFilters and EmptyRelationPropagation. FoldFilters can remove the filters which can be evaluated trivially. If Filter condition is alway false, replace it with an EmptyRelation
EmptyRelationPropagation can propagate the empty relation up to the tree, for example, inner join with EmptyRelation can return EmptyRelation.
@andygrove can you share a reproducer? We can then add it to the regression tests to make sure the empty filter is indeed eliminated and doesn't come back in
Datafusion only can propagate EmptyRelation just optimizer_config.max_passes times. Because we depend on multi-passes optimization to multiply elimination.
In other words, we currently don't have really EmptyRelationPropagation.
We can reproduce it.
After 3 optimizations, the plan still can continue to be eliminated.
CREATETABLEIF NOT EXISTS t1 ASVALUES(1,'HELLO'),(12,'DATAFUSION');
CREATETABLEIF NOT EXISTS t2 ASVALUES(1,'HELLO'),(12,'DATAFUSION');
CREATETABLEIF NOT EXISTS t3 ASVALUES(1,'HELLO'),(12,'DATAFUSION');
explain verbose select column1 from t1 join ( select column1 from t2 join (select column1 from t3 where false ) as ta2 ont2.column1=ta2.column1 ) as ta1 ont1.column1=ta1.column1;
Activity
mingmwang commentedon Oct 18, 2022
We can have two general rules:
FoldFiltersandEmptyRelationPropagation.FoldFilterscan remove the filters which can be evaluated trivially. IfFiltercondition is alway false, replace it with anEmptyRelationEmptyRelationPropagationcan propagate the empty relation up to the tree, for example, inner join withEmptyRelationcan returnEmptyRelation.mingmwang commentedon Oct 18, 2022
@andygrove Looks like there is already a rule
EliminateFilterfor this purpose.alamb commentedon Oct 18, 2022
Perhaps the changes in #3841 from @Dandandan made it possible to simplify the filter
Perhaps we could solve this issue by adding another run of
EliminateFilterat the end of the list in datafusion/optimizer/src/optimizer.rsalamb commentedon Oct 22, 2022
@andygrove can you share a reproducer? We can then add it to the regression tests to make sure the empty filter is indeed eliminated and doesn't come back in
jackwener commentedon Nov 12, 2022
Datafusion only can propagate
EmptyRelationjustoptimizer_config.max_passestimes. Because we depend on multi-passes optimization to multiply elimination.In other words, we currently don't have really
EmptyRelationPropagation.We can reproduce it.
After 3 optimizations, the plan still can continue to be eliminated.
andygrove commentedon Nov 14, 2022
FWIW, This is no longer an issue for me in Dask SQL. I am not sure what fixed it but maybe the multiple optimizer passes.