You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/29 03:25:21 UTC

[GitHub] [arrow-datafusion] liukun4515 opened a new pull request, #4411: optimize limit push for join case

liukun4515 opened a new pull request, #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411

   # Which issue does this PR close?
   
   
   add more join case which can be optimized for the `limit push down` rule.
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   # Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#discussion_r1034651792


##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,24 @@ impl OptimizerRule for LimitPushDown {
             LogicalPlan::Join(join) => {
                 let limit = fetch + skip;
                 let new_join = match join.join_type {
+                    JoinType::Left | JoinType::Right | JoinType::Full
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left and right
+                        push_down_join(join, Some(limit), Some(limit))
+                    }
+                    JoinType::LeftSemi | JoinType::LeftAnti
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left
+                        push_down_join(join, Some(limit), None)
+                    }
+                    JoinType::RightSemi | JoinType::RightAnti

Review Comment:
   add the `right semi` and `right anti`
   cc @jackwener 



-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#discussion_r1036386540


##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,24 @@ impl OptimizerRule for LimitPushDown {
             LogicalPlan::Join(join) => {
                 let limit = fetch + skip;
                 let new_join = match join.join_type {
+                    JoinType::Left | JoinType::Right | JoinType::Full
+                        if is_no_join_condition(join) =>

Review Comment:
   I wonder how often there will be no join conditions 🤔  that effectively then becomes a CROSS JOIN



-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] liukun4515 commented on pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#issuecomment-1330027122

   cc @jackwener 


-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] liukun4515 commented on pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#issuecomment-1331624320

   cc @Dandandan  if it looks good to you, I will merge this.


-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#discussion_r1036635219


##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,24 @@ impl OptimizerRule for LimitPushDown {
             LogicalPlan::Join(join) => {
                 let limit = fetch + skip;
                 let new_join = match join.join_type {
+                    JoinType::Left | JoinType::Right | JoinType::Full
+                        if is_no_join_condition(join) =>

Review Comment:
   > I wonder how often there will be no join conditions 🤔 that effectively then becomes a CROSS JOIN
   > 
   > To be clear I think the optimization is still correct, I just wonder how often it will appear in real queries
   
   Good question for this, in the current framework of optimizer in the datafusion, the `join` query will be converted to the `cross join` by other rule.
   
   The `limit push down` rule just do the best to optimize the plan.
   
   Some SQL are generated by the program, and the `join type` and `on condition` are added by the program, it will generate sql like ` select * from left_table right join right_table`.



-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
jackwener commented on code in PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#discussion_r1034659628


##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,18 @@ impl OptimizerRule for LimitPushDown {
             LogicalPlan::Join(join) => {
                 let limit = fetch + skip;
                 let new_join = match join.join_type {
+                    JoinType::Left | JoinType::Right | JoinType::Full
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left and right
+                        push_down_join(join, Some(limit), Some(limit))
+                    }
+                    JoinType::LeftSemi | JoinType::LeftAnti
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left
+                        push_down_join(join, Some(limit), None)
+                    }
                     JoinType::Left => push_down_join(join, Some(limit), None),
                     JoinType::Right => push_down_join(join, None, Some(limit)),

Review Comment:
   Understanded it



-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#discussion_r1034651266


##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,18 @@ impl OptimizerRule for LimitPushDown {
             LogicalPlan::Join(join) => {
                 let limit = fetch + skip;
                 let new_join = match join.join_type {
+                    JoinType::Left | JoinType::Right | JoinType::Full
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left and right
+                        push_down_join(join, Some(limit), Some(limit))
+                    }
+                    JoinType::LeftSemi | JoinType::LeftAnti

Review Comment:
   👍 good catch



-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] Dandandan commented on a diff in pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
Dandandan commented on code in PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#discussion_r1034367238


##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,18 @@ impl OptimizerRule for LimitPushDown {
             LogicalPlan::Join(join) => {
                 let limit = fetch + skip;
                 let new_join = match join.join_type {
+                    JoinType::Left | JoinType::Right | JoinType::Full
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left and right
+                        push_down_join(join, Some(limit), Some(limit))
+                    }
+                    JoinType::LeftSemi | JoinType::LeftAnti
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left
+                        push_down_join(join, Some(limit), None)
+                    }
                     JoinType::Left => push_down_join(join, Some(limit), None),
                     JoinType::Right => push_down_join(join, None, Some(limit)),

Review Comment:
   I think those are the lesser restrictive versions of push down (only to left/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@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#discussion_r1036386540


##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,24 @@ impl OptimizerRule for LimitPushDown {
             LogicalPlan::Join(join) => {
                 let limit = fetch + skip;
                 let new_join = match join.join_type {
+                    JoinType::Left | JoinType::Right | JoinType::Full
+                        if is_no_join_condition(join) =>

Review Comment:
   I wonder how often there will be no join conditions 🤔  that effectively then becomes a CROSS JOIN
   
   To be clear I think the optimization is still correct, I just wonder how often it will appear in real queries



-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] ursabot commented on pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#issuecomment-1333078366

   Benchmark runs are scheduled for baseline = 3fe542f2afcd5360edc9abb7ad1e8243b560a6b2 and contender = 48f0f3a78f7dfd6f175905fc31abbeecfd51766e. 48f0f3a78f7dfd6f175905fc31abbeecfd51766e is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/91e8bdff37d34663a3c283eba24ffc55...7b53b98871364304b74e066f0b6a368d/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/6c9f449254b44c219d235ccadec8d05c...c9b56ef9904546348de9a9d57bd5e623/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/234909a1237e447eaeb97f537f468fd4...f79a0172ea3e48c586eb9235b2e98506/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/8b60d13a4e2f4c55b74430dbc4171c9f...686e8317fcf848049bfa28178c53e97d/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] jackwener commented on pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
jackwener commented on PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#issuecomment-1330056116

   related issue to track problems like this #4413


-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] liukun4515 merged pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
liukun4515 merged PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411


-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
jackwener commented on code in PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#discussion_r1034276095


##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -606,6 +622,106 @@ mod test {
         assert_optimized_plan_eq(&outer_query, expected)
     }
 
+    #[test]
+    fn limit_should_push_down_join_without_condition() -> Result<()> {
+        let table_scan_1 = test_table_scan()?;
+        let table_scan_2 = test_table_scan_with_name("test2")?;
+        let left_keys: Vec<&str> = Vec::new();
+        let right_keys: Vec<&str> = Vec::new();
+        let plan = LogicalPlanBuilder::from(table_scan_1.clone())
+            .join(
+                &LogicalPlanBuilder::from(table_scan_2.clone()).build()?,
+                JoinType::Left,
+                (left_keys.clone(), right_keys.clone()),
+                None,
+            )?
+            .limit(0, Some(1000))?
+            .build()?;
+
+        let expected = "Limit: skip=0, fetch=1000\
+        \n  Left Join: \
+        \n    Limit: skip=0, fetch=1000\
+        \n      TableScan: test, fetch=1000\
+        \n    Limit: skip=0, fetch=1000\
+        \n      TableScan: test2, fetch=1000";
+
+        assert_optimized_plan_eq(&plan, expected).unwrap();
+
+        let plan = LogicalPlanBuilder::from(table_scan_1.clone())
+            .join(
+                &LogicalPlanBuilder::from(table_scan_2.clone()).build()?,
+                JoinType::Right,
+                (left_keys.clone(), right_keys.clone()),
+                None,
+            )?
+            .limit(0, Some(1000))?
+            .build()?;
+
+        let expected = "Limit: skip=0, fetch=1000\
+        \n  Right Join: \
+        \n    Limit: skip=0, fetch=1000\
+        \n      TableScan: test, fetch=1000\
+        \n    Limit: skip=0, fetch=1000\
+        \n      TableScan: test2, fetch=1000";
+
+        assert_optimized_plan_eq(&plan, expected).unwrap();

Review Comment:
   ```suggestion
           assert_optimized_plan_eq(&plan, expected)?;
   ```



##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,18 @@ impl OptimizerRule for LimitPushDown {
             LogicalPlan::Join(join) => {
                 let limit = fetch + skip;
                 let new_join = match join.join_type {
+                    JoinType::Left | JoinType::Right | JoinType::Full
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left and right
+                        push_down_join(join, Some(limit), Some(limit))
+                    }
+                    JoinType::LeftSemi | JoinType::LeftAnti
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left
+                        push_down_join(join, Some(limit), None)
+                    }
                     JoinType::Left => push_down_join(join, Some(limit), None),
                     JoinType::Right => push_down_join(join, None, Some(limit)),

Review Comment:
   remove these



##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,18 @@ impl OptimizerRule for LimitPushDown {
             LogicalPlan::Join(join) => {
                 let limit = fetch + skip;
                 let new_join = match join.join_type {
+                    JoinType::Left | JoinType::Right | JoinType::Full
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left and right
+                        push_down_join(join, Some(limit), Some(limit))
+                    }
+                    JoinType::LeftSemi | JoinType::LeftAnti

Review Comment:
   Forget `RightSemi/RightAnti`?



-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] jackwener commented on pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
jackwener commented on PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#issuecomment-1330045174

   A good improvement👍Thanks @liukun4515 


-- 
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@arrow.apache.org

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


[GitHub] [arrow-datafusion] liukun4515 commented on a diff in pull request #4411: optimize limit push for join case

Posted by GitBox <gi...@apache.org>.
liukun4515 commented on code in PR #4411:
URL: https://github.com/apache/arrow-datafusion/pull/4411#discussion_r1034542438


##########
datafusion/optimizer/src/limit_push_down.rs:
##########
@@ -192,6 +196,18 @@ impl OptimizerRule for LimitPushDown {
             LogicalPlan::Join(join) => {
                 let limit = fetch + skip;
                 let new_join = match join.join_type {
+                    JoinType::Left | JoinType::Right | JoinType::Full
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left and right
+                        push_down_join(join, Some(limit), Some(limit))
+                    }
+                    JoinType::LeftSemi | JoinType::LeftAnti
+                        if is_no_join_condition(join) =>
+                    {
+                        // push left
+                        push_down_join(join, Some(limit), None)
+                    }
                     JoinType::Left => push_down_join(join, Some(limit), None),
                     JoinType::Right => push_down_join(join, None, Some(limit)),

Review Comment:
   > remove these
   
   ```
   JoinType::Left | JoinType::Right | JoinType::Full
                           if is_no_join_condition(join) =>
   ```
   
   the `on condition` is empty, the rule can be applied, but if the `on condition` is not empty, 
   
   ```
        JoinType::Left => push_down_join(join, Some(limit), None),
                       JoinType::Right => push_down_join(join, None, Some(limit)),
   ```
   can be applied.
   
   cc @jackwener 



-- 
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@arrow.apache.org

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