Repository navigation
Implement support for RemotePushdownOptimizer - #643
Merged
Merged
Conversation
This PR impelements the extension-side support for the `RemotePushdownOptimizer` (duckdb/duckdb#22914, duckdb/duckdb#23135). Queries and statements that only reference tables of a single attached Postgres database are executed in Postgres as a whole (instead of scanning the tables and executing the query in DuckDB), when every construct they use can be translated to Postgres SQL with the same semantics. This covers e.g. joins, aggregates, window functions, CTEs, set operations, subqueries, many scalar functions, `UPDATE` / `DELETE` / `INSERT` (including `RETURNING` and `ON CONFLICT`), `CREATE TABLE ... AS`, `CREATE VIEW` and most `DROP` / `ALTER TABLE` statements. A pushed down query is executed as a single Postgres query over a single connection. Queries that are plain scans of a single table are instead executed through the regular table scan, which reads the table in parallel over multiple connections (by ranges of the `ctid`). A query is a plain scan when it reads a single table, selects only columns (or `*`), filters only with comparisons of columns with constants, `IN` lists and `IS [NOT] NULL` combined with `AND` / `OR`, and has no `ORDER BY` or `OFFSET` (a `LIMIT` is fine). For example, this query is still executed with a parallel scan: ```sql SELECT id, customer, amount FROM postgres_db.orders WHERE status = 'open' AND amount > 100 LIMIT 10; ``` Any other construct makes the query a candidate for pushdown, including seemingly simple ones such as a computed column, a `LIKE` filter or an `ORDER BY`. Remote pushdown is enabled by default. It can be disabled for newly attached databases (the setting is only read at `ATTACH` time): ```sql SET pg_enable_remote_pushdown = FALSE; ```
staticlibs
force-pushed
the
remote_pushdown
branch
from
October 29, 2026 10:21
a4832d0 to
5f01869
Compare
2 tasks done
1 of 2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR impelements the extension-side support for the
RemotePushdownOptimizer(duckdb/duckdb#22914, duckdb/duckdb#23135).Queries and statements that only reference tables of a single attached Postgres database are executed in Postgres as a whole (instead of scanning the tables and executing the query in DuckDB), when every construct they use can be translated to Postgres SQL with the same semantics. This covers e.g. joins, aggregates, window functions, CTEs, set operations, subqueries, many scalar functions,
UPDATE/DELETE/INSERT(includingRETURNINGandON CONFLICT),CREATE TABLE ... AS,CREATE VIEWand mostDROP/ALTER TABLEstatements.A pushed down query is executed as a single Postgres query over a single connection. Queries that are plain scans of a single table are instead executed through the regular table scan, which reads the table in parallel over multiple connections (by ranges of the
ctid). A query is a plain scan when it reads a single table, selects only columns (or*), filters only with comparisons of columns with constants,INlists andIS [NOT] NULLcombined withAND/OR, and has noORDER BYorOFFSET(aLIMITis fine). For example, this query is still executed with a parallel scan:Any other construct makes the query a candidate for pushdown, including seemingly simple ones such as a computed column, a
LIKEfilter or anORDER BY.Remote pushdown is enabled by default. It can be disabled for newly attached databases (the setting is only read at
ATTACHtime):