mongo_fdw
mongo_fdw copied to clipboard
Pushing down ORDER BY queries
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!
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.
@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
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.
Please let me know if you have any beta updates so I can give it a try.
Thanks!
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.. )
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.