Skip to content

Record CREATE FOREIGN TABLE in a pool of its own and resolve grants on it - #161

Open
LucaCappelletti94 wants to merge 9 commits into
mainfrom
upstream/create-foreign-table
Open

LucaCappelletti94 wants to merge 9 commits into
mainfrom
upstream/create-foreign-table

Conversation

@LucaCappelletti94

@LucaCappelletti94 LucaCappelletti94 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

sql-traits dropped CREATE FOREIGN TABLE without recording anything, so a schema that also granted on the foreign table failed to load with TableNotFoundForGrant. A foreign table is a relation in PostgreSQL (relkind f) that never carries row-level security, which makes a grant on it a full read of the remote relation, so a linter needs to see both the table and its grants.

The foreign table now goes into its own foreign_tables() pool beside tables(), which keeps answering only for relations that store their own rows, so callers asking about primary keys or row-level security on tables do not start seeing foreign tables. It uses the same node type as a table, so its columns, checks, owner, triggers and grants come from the existing table machinery. TableLike::foreign_source returns its SERVER and OPTIONS, and ColumnLike::foreign_options returns a column's own OPTIONS with keys folded as PostgreSQL stores them in attfdwoptions. Relation gains a ForeignTable variant, so grants, relation lookups and the relations a statement reads name it as its own kind, and ALL TABLES IN SCHEMA covers foreign tables as it does in PostgreSQL.

Ingestion follows what PostgreSQL 17 and 18 accept and refuse on a foreign table. ALTER TABLE column, rename and owner actions, triggers, LIKE, INHERITS in either direction, DROP FOREIGN TABLE and ATTACH PARTITION work on it, and partitions() and inheritors() list it. Column options stay with the column that declares them, so an inheriting table or a column added through a parent gets none. Key constraints, indexes, references to it, policies, row-level security and persistence changes, rules, DROP TABLE, and a unique index reaching it through a partitioned table are refused with the relation named as a foreign table, as are column OPTIONS on an ordinary table and an option list naming the same key twice. RuleOnMaterializedView and RuleOnSequence become RuleOnUnsupportedRelation so the rule refusal can name any of these kinds.

ALTER FOREIGN TABLE and CREATE FOREIGN TABLE ... PARTITION OF still wait on apache/datafusion-sqlparser-rs#2745 and #2753.

@LucaCappelletti94 LucaCappelletti94 added the enhancement New feature or request label Oct 28, 2026
@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/create-foreign-table branch 3 times, most recently from 08312d8 to 36b5dcd Compare October 31, 2026 12:44
@LucaCappelletti94
LucaCappelletti94 force-pushed the upstream/create-foreign-table branch from 36b5dcd to 9e5659b Compare November 1, 2026 11:49

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These duplicates are not on lines GitHub shows in this pull request diff, the inline comment cannot attach there. The links point at the copies on the head commit.

echoes · 👎 Report a wrong review · ❤️ Support echoes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant