Skip to content

Add extensions option for foreign servers - #426

Draft
iskakaushik wants to merge 1 commit into
mainfrom
extensions-option
Draft

iskakaushik wants to merge 1 commit into
mainfrom
extensions-option

Conversation

@iskakaushik

Copy link
Copy Markdown
Collaborator

What

Adds an extensions option for foreign servers, a comma-separated list of extension names, as in postgres_fdw:

ALTER SERVER ch OPTIONS (ADD extensions 'vector, re2');
  • Unset, the default: pg_clickhouse pushes down objects from every extension it supports and finds installed (hstore, re2, intarray, fuzzystrmatch, pgcrypto, pgvector). Nothing changes.
  • Set: only objects from the listed extensions push down. Objects from other extensions run in Postgres.

This lets a server keep an extension's functions and operators local, for example while a ClickHouse version mishandles one of them.

How it works

  • The validator parses the list with SplitIdentifierString(), like postgres_fdw's ExtractExtensionList(). A name that isn't installed gets a WARNING; bad list syntax is an ERROR.
  • clickhouseGetForeignRelSize() fills fpinfo->shippable_extensions, which was always NIL. It appends pg_clickhouse itself, so that its own functions, such as dictGet(), always push down, and so that a set list is never NIL.
  • chfdw_is_shippable() checks the list only after chfdw_check_for_custom_operator(), _function(), or _type() has recognized an object. So the option can only narrow pushdown, and the global custom object caches stay free of per-server state. Lookups go through the existing per-server ShippableCacheHash, which ALTER SERVER already invalidates.

Notes for review

  • Unlike postgres_fdw, listing an extension does not push down objects pg_clickhouse doesn't recognize, so that fallback path is gone. It was unreachable, and reviving it would let the option widen pushdown: unknown hstore operators would deparse by name.
  • Listing an installed extension that pg_clickhouse doesn't support, such as citext, has no effect and no warning, as the docs say. Warning would mean keeping a second list of supported extensions in sync with custom_types.c.
  • Tests cover vector sorts with the option set to hstore, set to vector, and unset in vector_pushdown.sql. They also cover intarray's idx() and the not-installed warning in udf.sql. vector_pushdown.sql creates hstore only for its block, so that extensions 'hstore' names an installed extension.

@iskakaushik
iskakaushik force-pushed the extensions-option branch 2 times, most recently from d30b267 to cf7a706 Compare October 15, 2026 23:41
pg_clickhouse pushes down objects from every extension it supports and
finds installed: hstore, re2, intarray, fuzzystrmatch, pgcrypto, and
pgvector. There was no way to keep an extension's objects local for a
server, and the `shippable_extensions` plumbing inherited from
postgres_fdw was dead code, always `NIL`.

Add the `extensions` server option, a comma-separated list of extension
names, as in postgres_fdw. The validator warns about extensions that
aren't installed. `clickhouseGetForeignRelSize()` parses the option into
`fpinfo->shippable_extensions` and adds pg_clickhouse itself, so that its
own functions always push down and a set list is never `NIL`.

`chfdw_is_shippable()` now checks that list after
`chfdw_check_for_custom_operator()`, `chfdw_check_for_custom_function()`,
or `chfdw_check_for_custom_type()` recognizes an object. The option thus
only narrows pushdown, and the global custom object cache holds no
per-server state. The check uses the per-server shippability cache to
avoid repeated `pg_depend` lookups. Nothing changes when the option is
unset.

Unlike postgres_fdw, listing an extension does not push down objects
pg_clickhouse doesn't recognize, so remove that fallback path. Listing an
extension pg_clickhouse doesn't support has no effect.

Test vector sorts with the option set to `hstore`, set to `vector`, and
unset in `vector_pushdown.sql`. Test the intarray `idx()` function and the
warning for an extension that isn't installed in `udf.sql`.
@theory theory added enhancement New feature or request interfaces Expand or improve interfaces for accessing ClickHouse dependencies Changes impacted by or requiring changes to dependencies labels Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Changes impacted by or requiring changes to dependencies enhancement New feature or request interfaces Expand or improve interfaces for accessing ClickHouse

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants