You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "nuno-faria (via GitHub)" <gi...@apache.org> on 2025/08/14 18:10:45 UTC

[I] Dynamic Filter Pushdown is being applied to the wrong table [datafusion]

nuno-faria opened a new issue, #17196:
URL: https://github.com/apache/datafusion/issues/17196

   ### Describe the bug
   
   In the following example, the Dynamic Filter Pushdown is built from `t2 (k, v)` and correctly pushed to `t1 (k)`, to reduce the number of scanned rows from `t1`:
   
   ```sql
   select *
   from t1 -- 1M rows, will become the right side
   join t2 on t1.k = t2.k
   where t2.v = 1000000; -- 1 row, will become the left side
   
   HashJoinExec join_type=Inner build_time=78.306µs, join_time=22.402µs
       DataSourceExec t2.parquet
           predicate=v@1 = 1000000
           output_rows=1
       DataSourceExec t1.parquet
           predicate=DynamicFilterPhysicalExpr [ k@0 >= 1000000 AND k@0 <= 1000000 ] -- dynamic filter added here
           output_rows=1 -- only returns 1 row
   ```
   
   Now if the `t2` side is greater than `t1`, then the order of the join switches, as the smaller relation becomes the build side. However, the Dynamic Filter Pushdown is still applied to the right relation (now `t2`) instead of `t1`:
   
   ```sql
   select *
   from t1 -- 1M rows, will become the left side
   join t2 on t1.k = t2.k
   where t2.v >= 1000000; -- 9M rows, will become the right side
   
   HashJoinExec join_type=Inner build_time=54.3462ms, join_time=2.403µs -- join is more expensive
       DataSourceExec t1.parquet
           output_rows=1000000
       DataSourceExec t2.parquet
           predicate=v@1 >= 1000000 AND DynamicFilterPhysicalExpr [ k@0 >= 3 AND k@0 <= 999998 ] -- dynamic filter added here
           output_rows=0 -- should be 1, possibly due to issue https://github.com/apache/datafusion/issues/17188
   ```
   
   ### To Reproduce
   
   ```sql
   copy (select i as k from generate_series(1, 1000000) t(i)) to 't1.parquet';
   copy (select i as k, i as v from generate_series(1, 10000000) t(i)) to 't2.parquet';
   create external table t1 stored as parquet location 't1.parquet';
   create external table t2 stored as parquet location 't2.parquet';
   
   -- works
   explain analyze select *
   from t1
   join t2 on t1.k = t2.k
   where t2.v = 1000000;
   
   -- pushed to the wrong relation
   explain analyze select *
   from t1
   join t2 on t1.k = t2.k
   where t2.v >= 1000000;
   ```
   
   ### Expected behavior
   
   Dynamic Filter applied to the correct table.
   
   ### Additional context
   
   _No response_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Dynamic Filter Pushdown is being applied to the wrong table [datafusion]

Posted by "xudong963 (via GitHub)" <gi...@apache.org>.
xudong963 commented on issue #17196:
URL: https://github.com/apache/datafusion/issues/17196#issuecomment-3191055926

   > the join won't use a `collectLeft` mode.
   
   So, the issue is the same as the one https://github.com/apache/datafusion/issues/17188? We need to consider the partitioned mode


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Dynamic Filter Pushdown is being applied to the wrong table [datafusion]

Posted by "nuno-faria (via GitHub)" <gi...@apache.org>.
nuno-faria commented on issue #17196:
URL: https://github.com/apache/datafusion/issues/17196#issuecomment-3191093292

   > So, the issue is the same as the one [#17188](https://github.com/apache/datafusion/issues/17188)? We need to consider the partitioned mode
   
   I don't think so, in this one the filter is being pushed to the wrong table, since it is always assumed that it should be pushed to the right relation. In the other the filter is pushed to the right relation, but the filter is incorrect.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Dynamic Filter Pushdown is being applied to the wrong table [datafusion]

Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb commented on issue #17196:
URL: https://github.com/apache/datafusion/issues/17196#issuecomment-3189512211

   Hmm I thought DataFusion didn't do smart switching of sides i.e. left side is always build side and right is always probe side?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Dynamic Filter Pushdown is being applied to the wrong table [datafusion]

Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb closed issue #17196: Dynamic Filter Pushdown is being applied to the wrong table
URL: https://github.com/apache/datafusion/issues/17196


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Dynamic Filter Pushdown is being applied to the wrong table [datafusion]

Posted by "nuno-faria (via GitHub)" <gi...@apache.org>.
nuno-faria commented on issue #17196:
URL: https://github.com/apache/datafusion/issues/17196#issuecomment-3189563371

   > Hmm I thought DataFusion didn't do smart switching of sides i.e. left side is always build side and right is always probe side?
   
   When there are statistics the planner selects the smaller side to be the build side.
   I think its done by the `join_selection` rule: https://github.com/apache/datafusion/blob/main/datafusion/physical-optimizer/src/join_selection.rs


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Dynamic Filter Pushdown is being applied to the wrong table [datafusion]

Posted by "adriangb (via GitHub)" <gi...@apache.org>.
adriangb commented on issue #17196:
URL: https://github.com/apache/datafusion/issues/17196#issuecomment-3189576101

   But won't that still result in the left side being the build side and the right side being the probe side -> let side is the dynamic filter source and we push them down into the right side?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Dynamic Filter Pushdown is being applied to the wrong table [datafusion]

Posted by "nuno-faria (via GitHub)" <gi...@apache.org>.
nuno-faria commented on issue #17196:
URL: https://github.com/apache/datafusion/issues/17196#issuecomment-3189605659

   Left side is always the build side, but the relation assigned to the left side can swap with the one on the right. In that case, the join won't use a `collectLeft` mode.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org