Skip to content

Refuse an unparsed VACUUM after empty statements, keep an NXDOMAIN final, and move to sqlparser 0.64 - #29

Merged
artem-pplx merged 8 commits into
mainfrom
fix-vacuum-check-after-semicolon
Nov 17, 2026
Merged

artem-pplx merged 8 commits into
mainfrom
fix-vacuum-check-after-semicolon

Conversation

@artem-pplx

@artem-pplx artem-pplx commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes a follow-up from the review of #28, settles how the DNS cache treats negative answers, and moves the query parser to sqlparser 0.64.

Unparsed VACUUM after empty statements

From this review comment (5f2391f, 682ea2e).

Postgres drops empty statements, so ;VACUUM (FULL) runs as a single VACUUM of every table, outside any implicit transaction block. first_word stopped at the leading ; and returned "", so rejects_unparsed forwarded the statement while a table was gated. It now skips ; along with whitespace and comments, repeatedly.

This also corrects a sentence in #28's description, which said only the first word matters because of the implicit transaction block. The first word is now found after any empty statements. A message with more than one non-empty statement still runs in an implicit transaction block, where VACUUM can't run.

Negative DNS answers

From this review comment and the follow-ups to it (c6e9a37, 392b6ea, 4efff4c).

c6e9a37 turned trust_negative_responses off on every system nameserver, as hickory-resolver 0.24 had it, so an NXDOMAIN from one server made the resolver ask the others. In 0.26 that has a cost 0.24 didn't have. Each attempt gets one timeout across all servers (name_server_pool.rs), and when it runs out the pool returns a timeout instead of the NXDOMAIN it already has. So an NXDOMAIN followed by a nameserver that doesn't answer became a timeout, retried for about 30 s with the default options (three tries each for A and AAAA, 5 s per try).

The DNS cache is meant to track what the connection itself will resolve. pgcat opens the connection through Tokio's lookup_host, which calls getaddrinfo, so the reference is the glibc stub resolver (res_send.c). These are the results from mock nameservers on localhost, for each kind of answer from the first server, with the servers asked one at a time. With the default options the first two servers are asked at once, and the first answer to arrive counts.

First server's answer trust-dns 0.22 / hickory 0.24 (before #27) glibc 2.43 #29 at 392b6ea This PR
NOERROR with an answer Used Used Used Used
NODATA Next server Final Final Final
NXDOMAIN Next server Final Next server Final
SERVFAIL Next server Next server Final, retried Final, retried (not configurable in 0.26)
REFUSED Next server Next server Final, retried Final, retried (not configurable in 0.26)
No answer Next server Next server after timeout Answer from the parallel server, if any Same (not configurable in 0.26)
NXDOMAIN, then a server that doesn't answer NXDOMAIN after 2 × timeout NXDOMAIN at once Timeout after 6 × timeout NXDOMAIN at once

4efff4c removes the loop, so NXDOMAIN is final again, as in glibc and in #28 as merged. The resolver is now built exactly as builder_tokio() builds it, plus the three option overrides from #28, so this PR doesn't change DNS behavior relative to main. It adds the tests and a doc comment that explains the choice.

The cost is the case from the review: with nameservers that see different zones, an NXDOMAIN from one of them is final, although another might resolve the host. glibc gives the same answer when that server is asked first.

The other rows can't be reached through hickory-resolver 0.26's configuration:

  • SERVFAIL and REFUSED: the pool returns any response-code error other than an untrusted NXDOMAIN (name_server_pool.rs). Upstream main moves on after SERVFAIL, but no release has that yet.
  • NODATA: the pool always returns it. glibc does too, except for a lame referral with no answer and neither AA nor RA set.
  • No answer: the next server is asked only within the same timeout, so with servers asked one at a time a silent first server ends the attempt.

sqlparser 0.64

(5d3ba0e, 57cd0c1, 9af00e6)

On 0.62, a query's parse time grows exponentially with nesting. 0.63 fixes several of these cases (upstream #2344, #2350, #2352, #2372 and #2392; changelog), and 0.64 fixes nested POSITION (#2619; changelog). The times below are from debug builds, with the parse on a worker thread bounded by recv_timeout:

SELECT + nesting 0.62 0.64
f( × 16 / 18 / 20 0.40 / 1.61 / 6.49 s
f( × 30 not done after 20 s 0.003 s
ROW( × 16 / 18 0.40 / 1.60 s
ROW( × 30 not done after 20 s 0.002 s
POSITION( × 12 / 14 2.24 / 20.1 s
POSITION( × 30 not done after 20 s 0.013 s
ARRAY[ × 47 0.002 s recursion-limit error, 0.008 s
ARRAY[ × 48 not done after 20 s (hits the recursion limit) recursion-limit error, 0.008 s

The port keeps pgcat's behavior except where 0.64 parses differently. Those changes are:

  • ONLY and * (#2770). FROM ONLY t, FROM ONLY (t), JOIN ONLY s.t, UPDATE ONLY t, DELETE FROM ONLY t, MERGE INTO ONLY t and t * now parse as markers on the real table. On 0.62 the parser read FROM ONLY t as a table named ONLY, aliased t, which pgcat refused, and some of the other forms didn't parse. Plugins now check the real table. With secrets gated, SELECT * FROM ONLY secrets is read and denied by table_access, and SELECT * FROM ONLY other is allowed. The parser still reads INSERT INTO ONLY t (which PostgreSQL rejects) as a table named ONLY, so that form is still refused. ALTER TABLE ONLY, LOCK TABLE ONLY and TRUNCATE ONLY parse as before.
  • CREATE [OR REPLACE] [MATERIALIZED] VIEW v now visits v as a relation (#2442), so table_access denies creating a view with a gated table's name, as it already did for CREATE TABLE.
  • These statements didn't parse before, and now they're routed by kind and checked by plugins, which see the relations sqlparser visits: ABORT, ALTER DEFAULT PRIVILEGES, ALTER [MATERIALIZED] VIEW, ALTER FOREIGN TABLE, ALTER TABLE with ATTACH/DETACH PARTITION, [NO] INHERIT, RESET (...) or SET LOGGED, ALTER TRIGGER, COMMENT ON FOREIGN TABLE, CREATE EXTENSION ... SCHEMA, CREATE/DROP FOREIGN TABLE, BEGIN ATOMIC function bodies, CREATE/DROP GROUP, CREATE OR REPLACE SCHEMA, CREATE/DROP RULE, EXCLUDE constraints, CREATE UNLOGGED TABLE, CREATE USER MAPPING, role GRANT/REVOKE, GRANT ... ALL ROUTINES, INSERT ... OVERRIDING, ON CONFLICT (a) WHERE, MERGE ... DO NOTHING, REFRESH MATERIALIZED VIEW and RESET SESSION AUTHORIZATION. sqlparser doesn't visit the partition named by ATTACH/DETACH PARTITION, the parent named by [NO] INHERIT, the parents in CREATE FOREIGN TABLE ... INHERITS, or the tables in DROP FOREIGN TABLE, so table_access now checks those itself, in any statement (57cd0c1, 9af00e6). The parents in CREATE [UNLOGGED] TABLE ... INHERITS are also checked explicitly (9af00e6). Without those checks, ALTER TABLE p ATTACH PARTITION secrets DEFAULT; SELECT * FROM p, CREATE UNLOGGED TABLE f (a int) INHERITS (secrets) and DROP FOREIGN TABLE secrets would have gone from refused to allowed. Plain CREATE TABLE ... INHERITS already parsed on 0.62, so with a gated parent it goes from allowed on main to denied. COMMENT ON FOREIGN TABLE was refused as unparsed before and is now parsed and allowed, like COMMENT ON TABLE. As on main, table_access doesn't see the tables named by COMMENT ON or by other DROP statements, or the new name in ALTER [MATERIALIZED] VIEW ... RENAME TO, which matches ALTER TABLE ... RENAME TO.
  • These query forms now parse: a bare SELECT, IS JSON, TRIM(FROM ...), XMLPARSE, ORDER BY ... USING, ::text COLLATE, right-nested joins, IN ((subquery), 2), FOR UPDATE before LIMIT, BETWEEN with a comparison and SELECT ... INTO a, b.
  • These no longer parse, so they take the unparsed path: string literals as aliases (SELECT 1 AS 'x', which PostgreSQL rejects; #2668), a string literal continued on the next line (SELECT 'a' + newline + 'b', which PostgreSQL reads as one string and 0.62 read as a string with an alias), SELECT * FROM limit, and ARRAY[ nested exactly 47 deep.

relations.rs (the metrics classifier) follows the AST changes: a TABLE command's names are now Idents, SELECT INTO has a list of targets, and index_hints is now index_directives. Its labels are unchanged.

Plugins receive the parsed Vec<Statement>, so plugins built outside this repository must move to 0.64 too. The changes they're most likely to hit are the IN variants merged into Expr::In (#2679), TableFactor::Table's new inheritance field and index_hints renamed to index_directives, SelectInto::targets, Table's names as Idents, Statement::Copy's new payload, and the new statement variants. The plugins needed no changes for the AST API port. table_access adds explicit checks for relation names the visitor skips (57cd0c1, 9af00e6).

The port also turned up statements after COPY ... FROM STDIN that plugins don't see. That's existing behavior, so it's fixed separately in #30, which is stacked on this PR.

Testing

On rustc 1.99.1:

  • test_unparsed_vacuum_is_rejected_while_a_table_is_gated now also covers these prefixes, through both a simple Query and a Parse message: ;, ; ;, ;;, /* c */;, ; -- c\n, /* a */;/* b */, and form feed, ;, vertical tab. With the old trim_start() line restored, each of these fails.
  • nxdomain_from_the_first_nameserver_is_final asks two mock UDP nameservers on localhost one at a time, in the given order. The first answers NXDOMAIN and the second an A record. The lookup must fail with NXDOMAIN, and the second server must get no queries. With c6e9a37's loop restored, it fails.
  • nxdomain_is_not_held_for_a_silent_nameserver asks a mock nameserver that answers NXDOMAIN and one that never answers, both at once (the default options). The lookup must fail with NXDOMAIN within 2 s (tokio::time::timeout), well before the silent server's 5 s timeout. With c6e9a37's loop restored, it fails after 2 s.
  • nxdomain_from_every_nameserver_fails checks that NXDOMAIN from every server is still an NXDOMAIN error.
  • The three DNS tests passed 50 of 50 runs, and 30 of 30 with the time bound.
  • test_nested_calls_parse_in_bounded_time parses f(, ROW( and POSITION( nested 30 deep, each on a worker thread, and needs each to parse within 1 s (recv_timeout, no sleeps). It also needs ARRAY[ nested 48 deep to return an error within 1 s. With the bump and the port reverted to 0.62, all four time out.
  • test_only_checks_the_real_table needs the ONLY and * forms above with secrets gated to parse and be denied, and SELECT * FROM ONLY other to be allowed. On 0.62, it fails because the query is refused as naming a table ONLY.
  • test_partitions_and_parents_are_checked gates secrets and requires a parse. The ATTACH PARTITION chain above, the public.secrets, quoted and FOR VALUES WITH forms, DETACH PARTITION, INHERIT, NO INHERIT after another operation, ALTER FOREIGN TABLE ... INHERIT, CREATE FOREIGN TABLE ... INHERITS, an INHERIT inside a BEGIN ATOMIC body, CREATE [UNLOGGED] TABLE ... INHERITS (with secrets, public.secrets or public."secrets" among the parents) and DROP FOREIGN TABLE (secrets, and IF EXISTS other, secrets CASCADE) must each be denied. ATTACH PARTITION other, ATTACH PARTITION "Secrets", INHERIT other, INHERITS (other) for foreign, plain and unlogged tables, and DROP FOREIGN TABLE other must be allowed. With 57cd0c1's table_access change reverted, it fails on the chain. With only 9af00e6's CREATE TABLE and DROP arms removed, it fails on CREATE TABLE f INHERITS (secrets), and with only the DROP arm removed, on DROP FOREIGN TABLE secrets.
  • test_plugins_require_parse now uses INSERT INTO ONLY for its ONLY cases, because the FROM ONLY and UPDATE ONLY cases it had now parse.
  • cargo fmt --check: clean.
  • cargo test --locked --features test-plugins: 389 unit tests and 4 doc-tests pass.
  • cargo clippy --locked --lib --examples --tests --features test-plugins: no warnings on the changed lines, and the same warning set as main.
  • Debug info was off for these builds (CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0) to save disk space.

Created with Perplexity

Postgres drops empty statements, so `;VACUUM (FULL)` runs as a single
VACUUM of every table. first_word stopped at the `;` and returned "",
so rejects_unparsed forwarded it while a table was gated. Skip `;`
along with whitespace and comments.

Co-authored-by: Perplexity <noreply@perplexity.ai>

@artem-pplx artem-pplx left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Raphael review of 5f2391f: CLEAR. This was 2 passes, Opus High and then a fresh Astra High, both on this head. D1 from #28 is fixed.

Checked:

  • Every iteration of first_word now drops ; together with whitespace (Rust's is_whitespace covers Postgres's [ \t\n\r\f\v]), nested block comments and CR/LF line comments.
  • No prefix that Postgres accepts still bypasses the check.
    • These return vacuum: /* a */;/* b */VACUUM, -- a\n;-- b\n;VACUUM, ;\f;\vVACUUM, and ;/**/;/* x /* y */ z */;\nVACUUM(FULL).
    • ;select 1; vacuum returns select. That's correct, because two non-empty statements run in an implicit transaction block, where VACUUM errors.
  • There is no over-refusal of valid SQL and no new panic path (; is ASCII).

Evidence:

  • The focused test passes. With :82 reverted it fails at :3713 on ;VACUUM (FULL).
  • cargo fmt --check is clean.
  • The 383-test lib receipt is reused from the identical base tree.

Description: accurate, and it correctly replaces #28's "only the first word…" sentence.

Nonblocking: one optional test addition, inline.

Created with Perplexity

Comment thread src/query_router.rs Resolved
artem-pplx and others added 2 commits November 16, 2026 23:02
Add `/* a */;/* b */VACUUM (FULL)` and a form feed and vertical tab
prefix to the unparsed VACUUM test, so the order in which first_word
skips comments, `;` and whitespace stays covered.

Co-authored-by: Perplexity <noreply@perplexity.ai>
hickory-resolver 0.24 built each system nameserver with
trust_negative_responses off, so an NXDOMAIN from one server made it ask
the others. 0.26 turns it on, so one server that doesn't know the
database host makes the lookup fail. Read the system configuration and
turn it off for every nameserver before building the resolver.

Co-authored-by: Perplexity <noreply@perplexity.ai>
@artem-pplx artem-pplx changed the title Refuse an unparsed VACUUM after empty statements Refuse an unparsed VACUUM after empty statements; retry other nameservers after an NXDOMAIN Nov 16, 2026

@artem-pplx artem-pplx left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review of c6e9a37: CLEAR. Two passes: Opus High, then a fresh Astra High, both on this head.

  • A1, the NXDOMAIN fallback, is fixed.
    • resolver_with makes the same calls builder_tokio() made in hickory-resolver 0.26.2. In order: read_system_conf, then builder_with_config with the default Tokio provider, then the options are replaced. The only addition is trust_negative_responses = false on every nameserver.
    • Both new DNS tests pass. The fallback test fails when the trust loop is removed.
  • D1 test additions: both new VACUUM prefixes pass, and each one fails when the fix is reverted.
  • Focused suite: 9/9 pass at this head. The author's fmt, clippy, 385 lib + 4 doc test results are reused, since nothing else changed.
  • Title and description: accurate, with the restoration explicitly scoped to NXDOMAIN.

Nonblocking:

  • One test-strength nit, inline.
  • Two follow-ups in hickory 0.26 that this PR doesn't change, in the separate comment below.

Created with Perplexity

Comment thread src/dns_cache.rs Resolved

Copy link
Copy Markdown
Collaborator Author

Follow-ups beyond this PR (hickory-resolver 0.26 behavior, nonblocking, from the c6e9a37 review):

  1. NODATA, SERVFAIL and REFUSED still stop fallback (P3).
    • In 0.26 the pool continues only after an untrusted NXDOMAIN. Empty NOERROR, SERVFAIL and REFUSED end the attempt; with sequential ordering, the other nameservers are never asked (probed with no sleeps; the second server got 0 queries). 0.24 kept asking for these when the servers were untrusted (source comparison).
    • Impact: a lookup miss leaves that connection without DNS-change tracking. The connection itself still opens.
    • Suggested: an upstream fix with regression tests, or a one-line note in the PR body that only NXDOMAIN is restored.
  2. NXDOMAIN plus a silent peer becomes Timeout and retries (P3).
    • The fallback now waits on the other nameserver. When the deadline passes, the pool returns Timeout instead of the stored NXDOMAIN, and RetryDnsHandle retries it. Probed with a 40 ms timeout: 6 attempts and Err(Timeout) after about 248 ms, against an immediate NXDOMAIN before this change.
    • With defaults (5 s timeout, 2 attempts, A then AAAA) this can take about 30 s, and an NXDOMAIN with an SOA loses negative caching.
    • Suggested: an upstream fix that keeps the stored error when the deadline passes. Don't set attempts = 0 here as a workaround, because that changes unrelated retry behavior.

Created with Perplexity

The test ordered the two answers with a 100 ms delay, so a scheduling
stall could let the A answer arrive first and the test pass without the
fix. Ask one nameserver at a time, in the given order, drop the delay,
and check that each nameserver got one query.

Co-authored-by: Perplexity <noreply@perplexity.ai>

Copy link
Copy Markdown
Collaborator Author

Both items are out of scope for #29, so there are no code changes for them here. This PR restores only the pre-0.26 NXDOMAIN fallback. Both items are hickory-resolver 0.26 behavior, and they're deferred upstream, to be tracked as follow-ups:

  1. NODATA, SERVFAIL and REFUSED still end the attempt instead of falling back to the other nameservers.
  2. NXDOMAIN plus a silent peer ends in Timeout and retries instead of the stored NXDOMAIN.

Created with Perplexity

@artem-pplx artem-pplx left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Review of 392b6ea: CLEAR. Two passes: Opus High, then a fresh Astra High, both on this head.

  • Test-only: the code outside #[cfg(test)] in dns_cache.rs is byte-identical to c6e9a37.
  • The P4 nit is fixed. The fallback test asks the servers one at a time in the given order, and the mock has no delay or sleep. The counters increment before the reply is sent, so the count assertions are race-free.
  • Evidence: the DNS tests pass 8/8 at this head. With the trust loop removed, the unchanged fallback test fails with NXDOMAIN.
  • Follow-ups: the two ledger items are deferred as upstream hickory behavior (noted).
  • Description: the testing section matches this head.

Created with Perplexity

c6e9a37 had hickory-resolver ask the other nameservers after an
NXDOMAIN, as 0.24 did. 0.26 limits a lookup to one timeout per server
and then returns a timeout instead of the error it already has, so an
NXDOMAIN followed by a nameserver that doesn't answer became a timeout,
retried for about 30 s with the default options. glibc, which resolves
the host when the connection is opened, takes the first NXDOMAIN as
final. Leave 0.26's default, so the cache gets the same answer at once.

Co-authored-by: Perplexity <noreply@perplexity.ai>
@artem-pplx artem-pplx changed the title Refuse an unparsed VACUUM after empty statements; retry other nameservers after an NXDOMAIN Refuse an unparsed VACUUM after empty statements; keep an NXDOMAIN final Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

This supersedes my earlier reply, which deferred both follow-ups. The goal is now behavior that matches the glibc stub resolver, which opens the connection through getaddrinfo, wherever hickory-resolver 0.26's configuration can express it. Each column below was checked against mock nameservers on localhost (the servers are asked one at a time):

First server's answer trust-dns 0.22 / hickory 0.24 glibc 2.43 392b6ea 4efff4c
NOERROR with an answer Used Used Used Used
NODATA Next server Final Final Final
NXDOMAIN Next server Final Next server Final
SERVFAIL Next server Next server Final, retried Final, retried
REFUSED Next server Next server Final, retried Final, retried
No answer Next server Next server after timeout Parallel server only Parallel server only
NXDOMAIN, then a server that doesn't answer NXDOMAIN after 2 × timeout NXDOMAIN at once Timeout after 6 × timeout (about 30 s) NXDOMAIN at once
  1. NXDOMAIN plus a silent peer is fixed in 4efff4c. It's caused by the NXDOMAIN fallback from c6e9a37: 0.26 gives each attempt one timeout across all servers and then returns a timeout instead of the stored NXDOMAIN (name_server_pool.rs). 4efff4c removes the fallback, so NXDOMAIN is final, as in glibc and in Fix the post-merge review findings from #27 #28 as merged. The tradeoff: the split-view case from the A1 comment ends in NXDOMAIN again, which matches glibc when that server is asked first. nxdomain_from_the_first_nameserver_is_final and nxdomain_is_not_held_for_a_silent_nameserver both fail with the fallback restored; the second one times out after 30 s.
  2. NODATA now matches glibc. SERVFAIL and REFUSED still don't, and this PR can't fix that: 0.26.x returns every response-code error except an untrusted NXDOMAIN (name_server_pool.rs), and no option changes it. Upstream main already moves on after SERVFAIL, but that isn't released yet. REFUSED is still a follow-up for upstream.

The PR body has the full table and the test results.

Created with Perplexity

On 0.62 a query's parse time grows exponentially with nesting: f( and
ROW( double it with each level (6.5 s at depth 20 in a debug build),
POSITION( about triples it, and ARRAY[ hangs once it nests as deep as
the recursion limit. 0.63 and 0.64 parse all of them at depth 30 in
milliseconds and refuse ARRAY[ nested 48 deep at once.

0.64 reads ONLY before a table in FROM, UPDATE, DELETE and MERGE, and
`t *`, as markers on the real table, so plugins now check that table
instead of the query being refused. The parser still reads
`INSERT INTO ONLY t` as a table named ONLY, so that's still refused.

relations.rs follows the AST changes (a TABLE command's names are
Idents, SELECT INTO has a list of targets, index_hints is now
index_directives) without changing its labels.

Co-authored-by: Perplexity <noreply@perplexity.ai>
@artem-pplx artem-pplx changed the title Refuse an unparsed VACUUM after empty statements; keep an NXDOMAIN final Refuse an unparsed VACUUM after empty statements, keep an NXDOMAIN final, and move to sqlparser 0.64 Nov 17, 2026

@artem-pplx artem-pplx left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Verdict at 5d3ba0e1: not clear, 1 blocker. This covers the delta since the cleared 392b6eaa: 4efff4c (DNS) and 5d3ba0e (sqlparser 0.64).

  • Blocker: Cargo.toml:32: ALTER TABLE ... ATTACH PARTITION <gated> newly parses and the partition name isn't checked (inline).
  • Nonblocking: nxdomain_is_not_held_for_a_silent_nameserver needs a time bound (inline). One description item is in a separate comment.

What holds:

  • The exponential parse is fixed. In a debug build, f( ×30 takes 2.1 ms, ROW( ×30 0.6 ms and POSITION( ×30 0.6 ms, and ARRAY[ ×48 hits the recursion limit in 8.6 ms.
  • No InList/InSubquery/InUnnest matches remain.
  • A 165-query probe compared 392b6ea with this head (parse required, secrets gated). Every other change went from refused or Allow to Deny: ONLY and t * in every position, views, BEGIN ATOMIC, rules, REFRESH and OVERRIDING.
  • Treating NXDOMAIN as final matches glibc and main.
  • cargo fmt --check is clean and the lib suite passes (388/388, --features test-plugins). Clippy shows no warnings on changed lines.

Limits. The probes were unit-level, through QueryRouter::parse and the plugins, not a live PostgreSQL. String function bodies (CREATE FUNCTION ... AS $$ ... $$) are unchecked on 0.62 as well as 0.64. That's pre-existing and is listed for follow-up at the end of the review.

Pass 1 of 2 (Opus, high effort). A second, independent pass with a different model follows on the fixed head.

Created with Perplexity

Comment thread Cargo.toml Resolved
Comment thread src/dns_cache.rs Resolved

Copy link
Copy Markdown
Collaborator Author

Nonblocking: one description item at 5d3ba0e1.

These statements didn't parse before, and now they're routed by kind and checked by plugins: ... ALTER TABLE with ATTACH/DETACH PARTITION, [NO] INHERIT ... COMMENT ON FOREIGN TABLE ... CREATE/DROP FOREIGN TABLE ...

The plugins only see the relations that sqlparser visits. At this head, table_access doesn't see the partition named by ATTACH/DETACH PARTITION or the parent named by [NO] INHERIT (see the Cargo.toml blocker). It also doesn't see the table named by COMMENT ON FOREIGN TABLE or DROP FOREIGN TABLE, which matches COMMENT ON TABLE / DROP TABLE on main.

Suggested wording once the blocker is fixed: "...routed by kind and checked by plugins, which see the relations sqlparser visits. table_access also checks the partition named by ATTACH/DETACH PARTITION and the parent named by [NO] INHERIT, which sqlparser doesn't visit. As on main, it doesn't see the tables named by COMMENT ON or DROP."

The other claims I checked match the head: the ONLY forms, the view change, the test count, the timing table, and "doesn't change DNS behavior relative to main".

Created with Perplexity

sqlparser 0.64 parses ATTACH PARTITION, DETACH PARTITION, INHERIT and
NO INHERIT in ALTER TABLE, and INHERITS in CREATE FOREIGN TABLE, which
0.62 didn't. It visits only the table altered or created, not the one
these name. So with a table gated and parse required,
`ALTER TABLE p ATTACH PARTITION secrets DEFAULT; SELECT * FROM p` went
from refused to allowed, and read secrets through p. table_access now
checks those names, in any statement.

nxdomain_is_not_held_for_a_silent_nameserver now waits at most 2 s for
the NXDOMAIN, so it fails if the answer is held, not only if it
changes.

Co-authored-by: Perplexity <noreply@perplexity.ai>
artem-pplx added a commit that referenced this pull request Nov 17, 2026
Co-authored-by: Perplexity <noreply@perplexity.ai>

Copy link
Copy Markdown
Collaborator Author

Updated the description at 57cd0c1 with that wording. It also names CREATE FOREIGN TABLE ... INHERITS, which table_access now checks as well, and the new name in ALTER [MATERIALIZED] VIEW ... RENAME TO, which, as on main for ALTER TABLE ... RENAME TO, it doesn't see.

Created with Perplexity

@artem-pplx artem-pplx left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Verdict at 57cd0c17: clear, no blockers. This covers the delta from the twice-cleared 392b6eaa.

  • The ATTACH PARTITION blocker is fixed. The check is recursive (visit_statements), and schema-qualified and quoted names are denied. Mutation-tested: stubbing the supplement fails test_partitions_and_parents_are_checked on the chain.
  • The DNS test is now bounded at 2 s.
  • The exponential parse is fixed. f(, ROW( and POSITION( nested ×30 parse in 0.4–3.7 ms (debug build), and ARRAY[ ×48 errors in 2.5 ms.
  • cargo +stable fmt --check is clean and the lib suite passes (389/389, --features test-plugins).
  • PostgreSQL 18.6 confirms that an unquoted BEGIN ATOMIC body rejects COPY, DROP and ALTER at CREATE FUNCTION. The router's top-level-only COPY check therefore has no executable gap there.

Nonblocking: CREATE [UNLOGGED] TABLE ... INHERITS and DROP FOREIGN TABLE names (inline, recommended in this PR); description items (separate comment). Pre-existing items are in a separate ledger comment.

Limits. These were unit-level router and plugin probes, plus one disposable PostgreSQL 18.6 cluster for DDL semantics. There was no end-to-end proxy run, low-privilege role matrix or loopback FDW setup.

Two passes: Opus (high effort) on 5d3ba0e, an Opus (high effort) check of the 57cd0c1 delta, and a fresh independent final with Astra (high effort) on this exact head.

Created with Perplexity

Comment thread src/plugins/table_access.rs Resolved

Copy link
Copy Markdown
Collaborator Author

Nonblocking: description items at 57cd0c17.

  1. The plugins in this repository needed no changes.

    The head adds checks to table_access. Suggested: "The plugins needed no changes for the AST API port. table_access adds explicit checks for relation names the visitor skips."

  2. As on main, table_access doesn't see the tables named by COMMENT ON or DROP (now including COMMENT ON FOREIGN TABLE and DROP FOREIGN TABLE)

    The FOREIGN TABLE forms didn't parse on 0.62, so with plugins_require_parse on, those exact statements were refused; now they're allowed. If the inline suggestion is taken, say these targets are checked. If not, say: "COMMENT ON FOREIGN TABLE and DROP FOREIGN TABLE were refused as unparsed before and are now parsed and allowed, like COMMENT ON TABLE and DROP TABLE."

  3. The list says CREATE UNLOGGED TABLE is now "checked by plugins", but its INHERITS parents aren't checked at this head. If the inline fix is taken, add: "The parents in CREATE [UNLOGGED] TABLE ... INHERITS are also checked explicitly."

The title is accurate.

Created with Perplexity

Copy link
Copy Markdown
Collaborator Author

Follow-up ledger (nonblocking, outside this PR's scope; posted once at the end of the review). All of these were already present on main before this PR:

  1. String function bodies aren't checked. CREATE FUNCTION f() RETURNS SETOF json LANGUAGE sql AS $$ SELECT row_to_json(s) FROM secrets s $$; SELECT * FROM f() is allowed on 0.62 and 0.64. This needs a policy decision: refuse string-bodied functions while a table is gated, apply the gated-name text check to bodies, or parse LANGUAGE sql bodies.
  2. Names visit_relations doesn't report: DROP TABLE/VIEW, GRANT/REVOKE ... ON, COMMENT ON TABLE, CREATE TRIGGER ... ON, CREATE TABLE ... (LIKE t), REFERENCES t(a) (usable as a row-existence oracle through FK errors), the SELECT ... INTO target, and the new name in ALTER ... RENAME TO. A single exhaustive check of statement name fields would cover them.
  3. Indirection through existing objects: an ungated parent, view or partition tree that already contains a gated table, and FDW OPTIONS (table_name '...') or dblink strings. This gate is syntactic, so its guarantee should be documented as name-based rather than object-identity isolation.
  4. SELECT ... INTO is routed as a read by is_mutation_set_expr.
  5. The COPY name check only looks at top-level statements. It's harmless today, because PostgreSQL rejects COPY in unquoted SQL function bodies, but a recursive visit_statements would remove that dependency.

Created with Perplexity

The visitor doesn't report the parents in CREATE [UNLOGGED] TABLE ...
INHERITS or the tables in DROP FOREIGN TABLE. 0.64 newly parses CREATE
UNLOGGED TABLE and DROP FOREIGN TABLE, so with plugins_require_parse on,
these were refused as unparsed before and allowed after the upgrade.
Rows inserted into a child table are read from its parent, so inheriting
from a gated table adds rows that its readers see.

table_access now checks both, as it checks CREATE FOREIGN TABLE ...
INHERITS.

Co-authored-by: Perplexity <noreply@perplexity.ai>
artem-pplx added a commit that referenced this pull request Nov 17, 2026
Co-authored-by: Perplexity <noreply@perplexity.ai>
@artem-pplx
artem-pplx added this pull request to stack #31 November 17, 2026 01:37

@artem-pplx artem-pplx left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Verdict at 9af00e68: clear, no findings. This covers the delta 57cd0c1..9af00e6.

  • The CreateTable.inherits and Drop { ForeignTable } arms are correct.
  • Each arm is independently mutation-tested: removing it fails test_partitions_and_parents_are_checked.
  • 28 more boundary probes passed: nested statements, qualified and quoted names, IF EXISTS/CASCADE/RESTRICT, multiple targets, and ungated controls.
  • PARTITION OF parents are already visited on 0.62 and 0.64, so they're denied.
  • The lib suite passes (389/389), and the description matches the head.

Security tier: an Opus (high effort) delta check, then a fresh independent final with Astra (high effort) on this exact head.

Created with Perplexity

@micahjz micahjz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verdict: APPROVE

PR/head: #29 at 9af00e6 against main/fac54a927739a29e52a0b1a3e1097491f71160ee.

Change/flow: Reviewed the full base-to-head diff, Query/Parse admission and unparsed refusal paths, table_access relation traversal, metrics AST port, and the resolver construction against hickory-resolver 0.26.2 source. The explicit resolver construction preserves the previous builder options and nameserver behavior.

Findings: No new blocking findings. ONLY checks the actual relation; the recursive supplement covers the added partition/inheritance/foreign-table paths. Empty statements no longer hide unparsed VACUUM. The existing COPY-tail gap is still present at this head and is closed by the separately reviewed #30; do not treat #29 alone as closing it.

Validation: Independently ran cargo test --locked --features test-plugins on a fresh package build of this head: 389 unit tests and 4 doc-tests pass. Also ran 32 SQL boundary cases through both Q and P messages against main, this head, and #30. The semicolon/comment VACUUM probe changes from forwarded to refused; the partition/parent cases remain denied or refused. All four nested-parser probes exceeded a 1-second deadline on main; this head completes them in approximately 2–19 ms, including the bounded ARRAY recursion error. Formatting and diff whitespace checks pass. Toolchain: rustc 1.100.0, debug info disabled. Current reported GitHub checks pass; an existing human approval is present.

Compatibility/rollout: Merge #29 before #30 and deploy the completed stack for COPY-tail coverage. External Rust plugins must port/rebuild with sqlparser 0.64 because Statement is part of the compile-time interface; this is not a new PostgreSQL wire or stored-data format. Rolling back restores the old parser/security behavior.

Exclusions: No code changes, merge, queue, deployment, live PostgreSQL/proxy integration test, private-plugin build, or production verification performed. This is a source-review approval, not deployment certification.

Created with Perplexity

@artem-pplx
artem-pplx merged commit 7fc219c into main Nov 17, 2026
6 checks passed
artem-pplx added a commit that referenced this pull request Nov 17, 2026
main now has #29 squashed. This branch already had all of #29, so the
conflicts are resolved to this branch's side and the tree is unchanged.

Co-authored-by: Perplexity <noreply@perplexity.ai>
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.

3 participants