Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unparse Sort with pushdown limit to SQL string #12873

Merged
merged 3 commits into from
Oct 14, 2024

Conversation

goldmedal
Copy link
Contributor

Which issue does this PR close?

no corresponding issue.

Rationale for this change

After the plan optimization, the limit could be pushed down to Sort. Unparser can't handle the pushdown limit currently.
Consider the following plan:

Sort: t1.age ASC NULLS FIRST, fetch=10
  Projection: t1.id, t1.age
    TableScan: t1

It should be unparsed to

SELECT t1.id, t1.age FROM t1 ORDER BY t1.age ASC NULLS FIRST LIMIT 10

What changes are included in this PR?

  • Unparse the Sort with the pushdown limit.

Are these changes tested?

yes

Are there any user-facing changes?

no

@github-actions github-actions bot added the sql SQL Planner label Oct 11, 2024
@goldmedal goldmedal marked this pull request as ready for review October 11, 2024 14:32
Copy link
Member

@findepi findepi left a comment

Choose a reason for hiding this comment

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

lgtm, but see question

input: Arc::clone(&sort.input),
fetch: None,
}));
let limit = Arc::new(LogicalPlan::Limit(Limit {
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to unparse without creating intermediate (fake) plan nodes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @findepi. Good idea. I tried it in d98169f. It's much better.

Copy link
Member

Choose a reason for hiding this comment

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

thanks!

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @goldmedal and @findepi

@alamb alamb merged commit 6e4bf05 into apache:main Oct 14, 2024
24 checks passed
hailelagi pushed a commit to hailelagi/datafusion that referenced this pull request Oct 14, 2024
* unparse Sort with push down limit

* cargo fmt

* set query limit directly
@goldmedal goldmedal deleted the feature/unparse-sort-with-pushdown-limit branch October 15, 2024 01:55
@goldmedal
Copy link
Contributor Author

Thanks @findepi @alamb 🙇

sgrebnov pushed a commit to spiceai/datafusion that referenced this pull request Oct 23, 2024
* unparse Sort with push down limit

* cargo fmt

* set query limit directly
sgrebnov added a commit to spiceai/datafusion that referenced this pull request Oct 24, 2024
* init (apache#12453)

* Fix unparse table scan with the projection pushdown (apache#12534)

* unparse the projection base on the source schema

* refactor and enhance the test

* Fix unparsing OFFSET (apache#12539)

* Unparse Sort with pushdown limit to SQL string (apache#12873)

* unparse Sort with push down limit

* cargo fmt

* set query limit directly

* Unparse `SubqueryAlias` without projections to SQL (apache#12896)

* change pub function comment to doc

* unparse subquery alias without projections

* fix tests

* rollback the empty line

* rollback the empty line

* exclude the table_scan with pushdown case

* fmt and clippy

* simplify the ast to string and remove unused debug code

* enhance unparsing plan with pushdown to avoid unnamed subquery (apache#13006)

* Update

---------

Co-authored-by: Lordworms <[email protected]>
Co-authored-by: Jax Liu <[email protected]>
Co-authored-by: Justus Flerlage <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants