Skip to content

Implement support for RemotePushdownOptimizer - #643

Merged
staticlibs merged 1 commit into
duckdb:mainfrom
staticlibs:remote_pushdown
Oct 29, 2026
Merged

staticlibs merged 1 commit into
duckdb:mainfrom
staticlibs:remote_pushdown

Conversation

@staticlibs

Copy link
Copy Markdown
Member

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:

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):

SET pg_enable_remote_pushdown = FALSE;

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;
```
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

Successfully merging this pull request may close these issues.

1 participant