You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "wiedld (via GitHub)" <gi...@apache.org> on 2024/09/09 17:37:53 UTC
[PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
wiedld opened a new pull request, #12399:
URL: https://github.com/apache/datafusion/pull/12399
**WIP: not yet ready for review.**
## Which issue does this PR close?
** TICKET TBD shortly.**
Closes #.
## Rationale for this change
First commit demonstrates the current, incorrect behavior where the offset is not applied correctly during limit pushdown.
Followup commits (TBD) will fix.
## What changes are included in this PR?
TBD
## Are these changes tested?
Yes.
## Are there any user-facing changes?
No.
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#discussion_r1754686284
##########
datafusion/physical-optimizer/src/limit_pushdown.rs:
##########
@@ -199,10 +203,15 @@ pub fn pushdown_limit_helper(
// This plan is combining input partitions, so we need to add the
// fetch info to plan if possible. If not, we must add a `LimitExec`
// with the information from the global state.
+ let mut new_plan = plan_with_fetch;
+ if global_state.skip > 0 {
Review Comment:
Added in cb7ded270
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#issuecomment-2343778532
> I think this may negate some of the performance improvements gained by the initial PR that introduced these bugs, but I think once this is merged, we can refactor the pushdown_limit_helper function slightly to keep the correct behavior while pulling in the improvements again
@itsjunetime I wonder if you can elaborate on this or file a ticket. In order to avoid the final `GlobalLimitExec` I believe we would have to add `offset` support into `SortPreservingMerge` and `TopK` -- which we could do, but I think the benefit might be relatively low
The implementation of Limit is pretty straightforward: https://github.com/apache/datafusion/blob/f24f2cbeff92937f59c5b22f27d23ebf347c3013/datafusion/physical-plan/src/limit.rs#L342-L404
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "wiedld (via GitHub)" <gi...@apache.org>.
wiedld commented on code in PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#discussion_r1750986767
##########
datafusion/sqllogictest/test_files/order.slt:
##########
@@ -1196,3 +1196,130 @@ physical_plan
02)--RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1
03)----SortExec: TopK(fetch=1), expr=[a@0 ASC NULLS LAST], preserve_partitioning=[false]
04)------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a, b], has_header=true
+
+
+####################
+# Test issue: TBD
+####################
Review Comment:
I just realized I put these tests in `order` (not `limit`).
I'll add a followup commit added now, to not mess up the commit history. Apologies.
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "wiedld (via GitHub)" <gi...@apache.org>.
wiedld commented on PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#issuecomment-2339194050
@mertak-synnada this is a fix to what we believe is a bug from this (very excellent) [change](https://github.com/apache/datafusion/pull/12003). We would appreciate your review 🙏🏼 .
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "wiedld (via GitHub)" <gi...@apache.org>.
wiedld commented on code in PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#discussion_r1752201316
##########
datafusion/physical-optimizer/src/limit_pushdown.rs:
##########
@@ -190,7 +194,8 @@ pub fn pushdown_limit_helper(
let skip_and_fetch = Some(global_fetch + global_state.skip);
- if pushdown_plan.supports_limit_pushdown() {
+ let global_skip = global_state.skip;
Review Comment:
Ah, that is better. Thank you.
Change pushed.
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#discussion_r1752696184
##########
datafusion/sqllogictest/test_files/limit.slt:
##########
@@ -565,3 +565,146 @@ physical_plan
statement ok
drop table data;
+
+
+####################
+# Test issue: limit pushdown with offsets
Review Comment:
```suggestion
# Test issue: limit pushdown with offsets
# Ensure the offset is not lost: https://github.com/apache/datafusion/issues/12423
```
##########
datafusion/sqllogictest/test_files/limit.slt:
##########
@@ -565,3 +565,146 @@ physical_plan
statement ok
drop table data;
+
+
+####################
+# Test issue: limit pushdown with offsets
+####################
+
+statement ok
+CREATE EXTERNAL TABLE ordered_table (
+ a0 INT,
+ a INT,
+ b INT,
+ c INT UNSIGNED,
+ d INT
+)
+STORED AS CSV
+WITH ORDER (c ASC)
+LOCATION '../core/tests/data/window_2.csv'
+OPTIONS ('format.has_header' 'true');
+
+# all results
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc;
+----
+3 25
+2 25
+1 0
+0 0
+
+# limit only
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc LIMIT 3;
+----
+3 25
+2 25
+1 0
+
+# offset only
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc OFFSET 1;
+----
+2 25
+1 0
+0 0
+
+# offset + limit
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc OFFSET 1 LIMIT 2;
+----
+2 25
+1 0
+
+# Applying offset & limit when multiple streams from groupby
+query TT
+EXPLAIN SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc OFFSET 1 LIMIT 2;
+----
+logical_plan
+01)Limit: skip=1, fetch=2
+02)--Sort: ordered_table.b DESC NULLS FIRST, fetch=3
+03)----Aggregate: groupBy=[[ordered_table.b]], aggr=[[sum(CAST(ordered_table.a AS Int64))]]
+04)------TableScan: ordered_table projection=[a, b]
+physical_plan
+01)GlobalLimitExec: skip=1, fetch=2
+02)--SortPreservingMergeExec: [b@0 DESC], fetch=3
+03)----SortExec: TopK(fetch=3), expr=[b@0 DESC], preserve_partitioning=[true]
+04)------AggregateExec: mode=FinalPartitioned, gby=[b@0 as b], aggr=[sum(ordered_table.a)]
+05)--------CoalesceBatchesExec: target_batch_size=8192
+06)----------RepartitionExec: partitioning=Hash([b@0], 4), input_partitions=4
+07)------------AggregateExec: mode=Partial, gby=[b@1 as b], aggr=[sum(ordered_table.a)]
+08)--------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+09)----------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a, b], has_header=true
+
+# Applying offset & limit when multiple streams from union
Review Comment:
```suggestion
# Applying offset & limit when multiple streams from union
# the plan must still have a global limit to apply the offset
```
##########
datafusion/physical-optimizer/src/limit_pushdown.rs:
##########
@@ -256,21 +265,24 @@ pub(crate) fn pushdown_limits(
pushdown_plan: Arc<dyn ExecutionPlan>,
global_state: GlobalRequirements,
) -> Result<Arc<dyn ExecutionPlan>> {
+ // Call pushdown_limit_helper.
+ // This will either extract the limit node (returning the child), or apply the limit pushdown.
Review Comment:
this might be a good comment to add to the `pushdown_limit_helper` function as well
##########
datafusion/sqllogictest/test_files/limit.slt:
##########
@@ -565,3 +565,146 @@ physical_plan
statement ok
drop table data;
+
+
+####################
+# Test issue: limit pushdown with offsets
+####################
+
+statement ok
+CREATE EXTERNAL TABLE ordered_table (
+ a0 INT,
+ a INT,
+ b INT,
+ c INT UNSIGNED,
+ d INT
+)
+STORED AS CSV
+WITH ORDER (c ASC)
+LOCATION '../core/tests/data/window_2.csv'
+OPTIONS ('format.has_header' 'true');
+
+# all results
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc;
+----
+3 25
+2 25
+1 0
+0 0
+
+# limit only
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc LIMIT 3;
+----
+3 25
+2 25
+1 0
+
+# offset only
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc OFFSET 1;
+----
+2 25
+1 0
+0 0
+
+# offset + limit
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc OFFSET 1 LIMIT 2;
+----
+2 25
+1 0
+
+# Applying offset & limit when multiple streams from groupby
+query TT
+EXPLAIN SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc OFFSET 1 LIMIT 2;
+----
+logical_plan
+01)Limit: skip=1, fetch=2
+02)--Sort: ordered_table.b DESC NULLS FIRST, fetch=3
+03)----Aggregate: groupBy=[[ordered_table.b]], aggr=[[sum(CAST(ordered_table.a AS Int64))]]
+04)------TableScan: ordered_table projection=[a, b]
+physical_plan
+01)GlobalLimitExec: skip=1, fetch=2
+02)--SortPreservingMergeExec: [b@0 DESC], fetch=3
+03)----SortExec: TopK(fetch=3), expr=[b@0 DESC], preserve_partitioning=[true]
+04)------AggregateExec: mode=FinalPartitioned, gby=[b@0 as b], aggr=[sum(ordered_table.a)]
+05)--------CoalesceBatchesExec: target_batch_size=8192
+06)----------RepartitionExec: partitioning=Hash([b@0], 4), input_partitions=4
+07)------------AggregateExec: mode=Partial, gby=[b@1 as b], aggr=[sum(ordered_table.a)]
+08)--------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+09)----------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a, b], has_header=true
+
+# Applying offset & limit when multiple streams from union
+query TT
+explain select * FROM (
+ select c FROM ordered_table
+ UNION ALL
+ select d FROM ordered_table
+) order by 1 desc LIMIT 10 OFFSET 4;
+----
+logical_plan
+01)Limit: skip=4, fetch=10
+02)--Sort: ordered_table.c DESC NULLS FIRST, fetch=14
+03)----Union
+04)------Projection: CAST(ordered_table.c AS Int64) AS c
+05)--------TableScan: ordered_table projection=[c]
+06)------Projection: CAST(ordered_table.d AS Int64) AS c
+07)--------TableScan: ordered_table projection=[d]
+physical_plan
+01)GlobalLimitExec: skip=4, fetch=10
+02)--SortPreservingMergeExec: [c@0 DESC], fetch=14
+03)----UnionExec
+04)------SortExec: TopK(fetch=14), expr=[c@0 DESC], preserve_partitioning=[true]
+05)--------ProjectionExec: expr=[CAST(c@0 AS Int64) as c]
+06)----------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+07)------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[c], output_ordering=[c@0 ASC NULLS LAST], has_header=true
+08)------SortExec: TopK(fetch=14), expr=[c@0 DESC], preserve_partitioning=[true]
+09)--------ProjectionExec: expr=[CAST(d@0 AS Int64) as c]
+10)----------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
+11)------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[d], has_header=true
+
+# ApplyingmLIMIT & OFFSET to subquery.
Review Comment:
```suggestion
# Applying LIMIT & OFFSET to subquery.
```
##########
datafusion/physical-optimizer/src/limit_pushdown.rs:
##########
@@ -199,10 +203,15 @@ pub fn pushdown_limit_helper(
// This plan is combining input partitions, so we need to add the
// fetch info to plan if possible. If not, we must add a `LimitExec`
// with the information from the global state.
+ let mut new_plan = plan_with_fetch;
+ if global_state.skip > 0 {
Review Comment:
is it worth a comment explaining *why* a skip means we can't apply this rule?
##########
datafusion/sqllogictest/test_files/limit.slt:
##########
@@ -565,3 +565,146 @@ physical_plan
statement ok
drop table data;
+
+
+####################
+# Test issue: limit pushdown with offsets
+####################
+
+statement ok
+CREATE EXTERNAL TABLE ordered_table (
+ a0 INT,
+ a INT,
+ b INT,
+ c INT UNSIGNED,
+ d INT
+)
+STORED AS CSV
+WITH ORDER (c ASC)
+LOCATION '../core/tests/data/window_2.csv'
+OPTIONS ('format.has_header' 'true');
+
+# all results
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc;
+----
+3 25
+2 25
+1 0
+0 0
+
+# limit only
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc LIMIT 3;
+----
+3 25
+2 25
+1 0
+
+# offset only
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc OFFSET 1;
+----
+2 25
+1 0
+0 0
+
+# offset + limit
+query II
+SELECT b, sum(a) FROM ordered_table GROUP BY b order by b desc OFFSET 1 LIMIT 2;
+----
+2 25
+1 0
+
+# Applying offset & limit when multiple streams from groupby
Review Comment:
For explain plans I think it helps to add a comment explaining what is being tested -- this helps future people understand if updates to the plans are acceptable
```suggestion
# Applying offset & limit when multiple streams from groupby
# the plan must still have a global limit to apply the offset
```
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#issuecomment-2343768845
I am going to make the comment suggestions to this PR so we can merge it in.
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#issuecomment-2344587207
Thanks everyone for your help getting this done!
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "wiedld (via GitHub)" <gi...@apache.org>.
wiedld commented on code in PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#discussion_r1750986767
##########
datafusion/sqllogictest/test_files/order.slt:
##########
@@ -1196,3 +1196,130 @@ physical_plan
02)--RepartitionExec: partitioning=RoundRobinBatch(2), input_partitions=1
03)----SortExec: TopK(fetch=1), expr=[a@0 ASC NULLS LAST], preserve_partitioning=[false]
04)------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[a, b], has_header=true
+
+
+####################
+# Test issue: TBD
+####################
Review Comment:
I just realized we put these tests in `order` (not `limit`).
I'll add a followup commit added now, to not mess up the commit history. Apologies.
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "mertak-synnada (via GitHub)" <gi...@apache.org>.
mertak-synnada commented on PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#issuecomment-2343829295
> > I think this may negate some of the performance improvements gained by the initial PR that introduced these bugs, but I think once this is merged, we can refactor the pushdown_limit_helper function slightly to keep the correct behavior while pulling in the improvements again
>
> @itsjunetime I wonder if you can elaborate on this or file a ticket. In order to avoid the final `GlobalLimitExec` I believe we would have to add `offset` support into `SortPreservingMerge` and `Sort(TopK)` -- which we could do, but I think the benefit might be relatively low
>
> The implementation of Limit is pretty straightforward:
>
> https://github.com/apache/datafusion/blob/f24f2cbeff92937f59c5b22f27d23ebf347c3013/datafusion/physical-plan/src/limit.rs#L342-L404
I believe @itsjunetime mentioned for the first commit, but after my change suggestion, the gains should be preserved, imo.
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #12399:
URL: https://github.com/apache/datafusion/pull/12399
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "wiedld (via GitHub)" <gi...@apache.org>.
wiedld commented on code in PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#discussion_r1752201316
##########
datafusion/physical-optimizer/src/limit_pushdown.rs:
##########
@@ -190,7 +194,8 @@ pub fn pushdown_limit_helper(
let skip_and_fetch = Some(global_fetch + global_state.skip);
- if pushdown_plan.supports_limit_pushdown() {
+ let global_skip = global_state.skip;
Review Comment:
That is better. Thank you.
Change pushed.
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#issuecomment-2338954300
cc @itsjunetime
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "mertak-synnada (via GitHub)" <gi...@apache.org>.
mertak-synnada commented on code in PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#discussion_r1751627355
##########
datafusion/physical-optimizer/src/limit_pushdown.rs:
##########
@@ -190,7 +194,8 @@ pub fn pushdown_limit_helper(
let skip_and_fetch = Some(global_fetch + global_state.skip);
- if pushdown_plan.supports_limit_pushdown() {
+ let global_skip = global_state.skip;
Review Comment:
Thank you very much for revealing this!
In this `LimitPushdown` optimizer we remove all the `LimitExec`s assuming they might be redundant, assigning them to global_state and then optimizing the plan, and re-adding them if necessary. But in this case, it looks like we forgot to re-add when we're adding the fetch info to SPM.
So rather than overriding `supports_limit_pushdown` API, I think we should handle this where it's happenning. What would you think, solving this with below suggestion?
If you can provide me write permission to your repository I can also commit this change.
```suggestion
if pushdown_plan.supports_limit_pushdown() {
if !combines_input_partitions(&pushdown_plan) {
// We have information in the global state and the plan pushes down,
// continue:
Ok((Transformed::no(pushdown_plan), global_state))
} else if let Some(plan_with_fetch) = pushdown_plan.with_fetch(skip_and_fetch) {
// This plan is combining input partitions, so we need to add the
// fetch info to plan if possible. If not, we must add a `LimitExec`
// with the information from the global state.
let mut new_plan = plan_with_fetch;
if global_state.skip > 0 {
new_plan =
add_global_limit(new_plan, global_state.skip, global_state.fetch);
}
global_state.fetch = skip_and_fetch;
global_state.skip = 0;
global_state.satisfied = true;
Ok((Transformed::yes(new_plan), global_state))
} else if global_state.satisfied {
```
--
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: [PR] Fix incorrect OFFSET during LIMIT pushdown. [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #12399:
URL: https://github.com/apache/datafusion/pull/12399#issuecomment-2341972683
I have filed https://github.com/apache/datafusion/issues/12423 to track this issue and updated this PR description
--
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