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

Pushing down ORDER BY queries #161

Open
iosifnicolae2 opened this issue Jun 10, 2022 · 6 comments
Open

Pushing down ORDER BY queries #161

iosifnicolae2 opened this issue Jun 10, 2022 · 6 comments

Comments

@iosifnicolae2
Copy link

Use case

I have the following query:

SELECT
          *
        FROM
          "unit"."record"
        ORDER BY
          "timestamp" DESC NULLS FIRST
        LIMIT
          1

QUERY PLAN:

Limit  (cost=1030.00..1030.00 rows=1 width=168)
Output: _id, unit_id, "timestamp", data
->  Sort  (cost=1030.00..1032.50 rows=1000 width=168)
Output: _id, unit_id, "timestamp",  data
Sort Key: record."timestamp" DESC
->  Foreign Scan on unit.record  (cost=25.00..1025.00 rows=1000 width=168)
Output: _id, unit_id, "timestamp",  data
Foreign Namespace: XX-db.unit_records
Query Identifier: 2397074415654613066

The problem

The query is very slow, most likely the extension is fetching all the rows then order them in PostgresSQL.

Question

How can I implement ORDER BY push-down so that PostgreSQL receives just the first row? cc @jeevanchalke

Thank you!

@vaibhavdalvi93
Copy link

Thanks, @iosifnicolae2 for raising an issue.

The ORDER BY and/or LIMIT/OFFSET push-downs are currently not supported. However, the same is on our roadmap and we already started working on it.

@iosifnicolae2
Copy link
Author

iosifnicolae2 commented Jun 10, 2022

@vaibhavdalvi93 thank you for the reply.

How can I help? Do you happen to have a rough estimate on how much would it take to be pushed on the master branch?

Thanks!

PS. (off-topic) This extension would be very helpful for people currently using Hasura

@jeevanchalke
Copy link

We are planning to get both these pushdowns checked-in in the next quarter.

Thanks for using the extension. Your constant feedback and feature requests are all welcome.

@iosifnicolae2
Copy link
Author

Please let me know if you have any beta updates so I can give it a try.

Thanks!

@iosifnicolae2
Copy link
Author

Also, would it possible to push-down LIMIT operator? (we're querying a big database and unfortunetly the extension is not feasible for our use-case yet.. )

@jeevanchalke
Copy link

Yes. We are working on both the push-downs.

Note that, if the query has an ORDER BY clause as well as a LIMIT clause, then only LIMIT can't be pushed down if ORDER BY doesn't. As LIMIT's output depended on the sorted result-set. So if your query has both clauses, then essentially you need both these pushdowns. So we are working on them in parallel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants