Skip to content

Push down compatible UNION queries and grouped set operations - #324

Open
k-bx wants to merge 2 commits into
ClickHouse:mainfrom
k-bx:agent/union-cte-pushdown
Open

Push down compatible UNION queries and grouped set operations#324
k-bx wants to merge 2 commits into
ClickHouse:mainfrom
k-bx:agent/union-cte-pushdown

Conversation

@k-bx

@k-bx k-bx commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Add foreign-path and deparsing support for compatible PostgreSQL set-operation relations.

Planner changes

  • recognize set-operation arms backed by compatible pg_clickhouse foreign paths
  • require the same foreign server and effective user mapping for every arm
  • deparse compatible UNION ALL and UNION DISTINCT trees as a single remote query
  • preserve target-column positions and renumber parameters across arms
  • support conservative plain DISTINCT pushdown
  • allow compatible grouping and aggregation above flattened UNION ALL relations
  • allow inlined CTEs to participate without changing materialized CTE behavior
  • reject unsupported types, table engines, ordering, HAVING, mixed servers, local conditions, and parameterized paths

Unsupported shapes are not given a foreign path and retain their existing planner behavior.

Validation

  • project pre-commit checks
  • clean PostgreSQL 18 build with warnings treated as errors
  • focused planner and execution regressions for binary and HTTP drivers
  • real-world production canary validation with a multi-table analytical workload using UNION ALL and grouped COUNT(DISTINCT ...); verified result parity, remote execution of the combined query, and stable repeated execution on production-scale data

@k-bx
k-bx marked this pull request as ready for review July 24, 2026 05:29
@theory theory added pushdown Improvements to query pushdown sql Improve SQL coverage or FDW capabilities labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pushdown Improvements to query pushdown sql Improve SQL coverage or FDW capabilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants