Skip to content

Support Limit pushdown for MemoryExec - #14502

Closed
zjregee wants to merge 2 commits into
apache:mainfrom
zjregee:impl-fetch-limit-for-memory-exec
Closed

Support Limit pushdown for MemoryExec#14502
zjregee wants to merge 2 commits into
apache:mainfrom
zjregee:impl-fetch-limit-for-memory-exec

Conversation

@zjregee

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes#14337.

Rationale for this change

What changes are included in this PR?

Implement limit pushdown for MemoryExec, add unit test and modify outdated content in .slt test files.

Are these changes tested?

Yes.

Are there any user-facing changes?

None.

@github-actionsgithub-actionsBot added physical-expr Changes to the physical-expr crates sqllogictest SQL Logic Tests (.slt) labels Feb 5, 2025
@zjregee
zjregeeforce-pushed the impl-fetch-limit-for-memory-exec branch from 02efd60 to 13a0960CompareFebruary 5, 2025 09:43
@zjregee
zjregeeforce-pushed the impl-fetch-limit-for-memory-exec branch from 13a0960 to 38edfcfCompareFebruary 5, 2025 10:48
@github-actionsgithub-actionsBot added the core Core DataFusion crate label Feb 5, 2025

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @zjregee ❤️

I have some small suggestions but we could do them as a follow on PR as well (they are not required to merge this PR in my opinion)

Thanks!

projection: Option<Vec<usize>>,
/// Index into the data
index: usize,
/// The remaining number of rows to return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// The remaining number of rows to return
/// The remaining number of rows to return. If None, all rows are returned

Comment on lines +548 to +552
if self.fetch.is_none() {
return Poll::Ready(Some(Ok(batch)));
}

let fetch = self.fetch.unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can write this more concisely and avoid the unwrap with something like

Suggested change
ifself.fetch.is_none(){
returnPoll::Ready(Some(Ok(batch)));
}
let fetch = self.fetch.unwrap();
letSome(&fetch) = self.fetch.as_ref()else{
returnPoll::Ready(Some(Ok(batch)));
};

05)--------MemoryExec: partitions=1, partition_sizes=[1]
06)------GlobalLimitExec: skip=0, fetch=10
07)--------MemoryExec: partitions=1, partition_sizes=[1]
04)------MemoryExec: partitions=1, partition_sizes=[1], limit=1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😍

@ozankabak

Copy link
Copy Markdown
Contributor

@alamb, this is subsumed by the unified source PR. Let's only merge this if we encounter an issue that will delay the other one, but let's hold off otherwise to avoid conflicts

@alambalamb changed the title impl limit pushdown for MemoryExecSupport Limit pushdown for MemoryExecFeb 5, 2025
@alamb

alamb commented Feb 5, 2025

Copy link
Copy Markdown
Contributor

@alamb, this is subsumed by the unified source PR. Let's only merge this if we encounter an issue that will delay the other one, but let's hold off otherwise to avoid conflicts

Sounds good

FWIW I think @ozankabak is talking about this PR:

@alamb

alamb commented Feb 6, 2025

Copy link
Copy Markdown
Contributor

Thank you for your patience @zjregee -- and I apologize that this feature was already underway when I field #14224

I am quite sorry if you feel your time was wasted.

@zjregee
zjregee deleted the impl-fetch-limit-for-memory-exec branch February 7, 2025 03:29
@zjregee

Copy link
Copy Markdown
MemberAuthor

It seems that the suggestions mentioned here are still feasible. I will use a follow on PR to add this.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coreCore DataFusion cratephysical-exprChanges to the physical-expr cratessqllogictestSQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement fetch limit for MemoryExec

3 participants

@zjregee@ozankabak@alamb