Query Pushdown
Query pushdown is a technique that enhances query performance by executing parts of the query directly on the data source. It reduces data transfer between the database and the application, enabling faster execution and improved performance.
What is Query Pushdown?
Query pushdown is a technique that enhances query performance by executing parts of the query directly on the data source. It reduces data transfer between the database and the application, enabling faster execution and improved performance.

Using Query Pushdown
In Wrappers, the pushdown logic is integrated into each FDW. You don't need to modify your queries to benefit from this feature. For example, the Stripe FDW automatically applies query pushdown for id within the customer object:
1 2 3 | |
This approach contrasts with fetching and filtering all customers locally, which is less efficient. Query pushdown translates this into a single API call, significantly speeding up the process:
1 | |
We can use push down criteria and other query parameters too. For example, ClickHouse FDW supports order by and limit pushdown:
1 2 3 4 | |
This query executes order by name limit 20 on ClickHouse before transferring the result to Postgres.
Aggregate Pushdown
Aggregate pushdown allows aggregate functions like COUNT, SUM, AVG, MIN, and MAX to be executed directly on the foreign data source. This is especially valuable for analytics queries where you only need summary statistics rather than raw data.
1 2 3 | |
Instead of fetching all matching rows and computing aggregates locally, the FDW can push the entire aggregation to the remote source. This dramatically reduces data transfer - returning just a single row with the computed values.
GROUP BY Support
FDWs that support aggregate pushdown can also support GROUP BY pushdown:
1 2 3 | |
This executes the grouping and aggregation on the remote server, returning only the grouped results.
Supported Aggregate Functions
The Wrappers framework supports pushing down these aggregate functions:
| Function | Description |
|---|---|
COUNT(*) |
Count all rows |
COUNT(column) |
Count non-null values |
COUNT(DISTINCT column) |
Count unique non-null values |
SUM(column) |
Sum of values |
AVG(column) |
Average of values |
MIN(column) |
Minimum value |
MAX(column) |
Maximum value |
Implementing Aggregate Pushdown
FDW developers can enable aggregate pushdown by implementing these trait methods:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
See the API documentation for detailed information on implementing aggregate pushdown.