Skip to content

test(pg_catalog): failing OID-stability regressions for #389 / #390#392

Closed
sunng87 wants to merge 1 commit into
datafusion-contrib:masterfrom
GreptimeTeam:test/pg-catalog-oid-stability
Closed

test(pg_catalog): failing OID-stability regressions for #389 / #390#392
sunng87 wants to merge 1 commit into
datafusion-contrib:masterfrom
GreptimeTeam:test/pg-catalog-oid-stability

Conversation

@sunng87

@sunng87 sunng87 commented Jul 21, 2026

Copy link
Copy Markdown
Member

What

A test-only change that adds failing regression tests reproducing the pg_catalog OID instability described in #389 (and the related #390). No production code is changed.

The intent is to provide a concrete, runnable reproduction that can be used to validate fix candidates — in particular PR #391.

Why these tests

Pooled PostgreSQL clients (DBeaver, JDBC drivers, …) resolve an OID on one connection and reference it on another via joins such as pg_class WHERE relnamespace = <oid>. Those OIDs must therefore be:

  1. stable across catalog-table queries within a session (a schema's OID must not change just because another catalog table was queried), and
  2. join-consistent (pg_class.relnamespace must equal the pg_namespace.oid a client resolved earlier).

Additionally, the static catalog rows this crate ships reference the canonical pg_catalog namespace OID 11 (e.g. pg_type.typnamespace = 11, pg_proc.pronamespace = 11), so pg_catalog must keep that fixed OID.

The tests (all currently fail on master)

Test Reproduces Fails on master with
schema_oid_is_stable_across_pg_attribute_query #389 — OID drift after pg_attribute evicts the shared OID cache 16385 != 16457
pg_class_resolves_table_via_namespace_oid #389 — the DBeaver symptom (WHERE relnamespace = <oid> matches nothing) got 0
pg_catalog_namespace_keeps_fixed_oid_eleven #390pg_catalog must keep OID 11 16385 != 11

Root cause being captured

The dynamic catalog tables (pg_namespace, pg_class, pg_attribute, pg_database) share one OID counter + cache, but each builder rewrites that cache differently. Notably pg_attribute does *oid_cache = swap_cache with table-only keys, evicting every Catalog/Schema OID; the next pg_namespace/pg_class query then re-assigns the schema a different OID via the counter, so an OID a client resolved earlier no longer matches.

Verification

# master (this PR) -> tests FAIL (bug reproduced)
cargo test -p datafusion-pg-catalog --lib oid

# with PR #391 applied on top -> tests PASS (fix confirmed)

I confirmed all three tests fail on master and pass once #391 is applied. cargo fmt --check and cargo clippy --all-features -- -D warnings are clean, so the only CI signal here is the intended cargo test failure.

Notes

Refs #389, #390, #391.

…n-contrib#389 / datafusion-contrib#390

Pooled PostgreSQL clients (DBeaver, JDBC, ...) resolve an OID on one
connection and reference it on another via joins such as
`pg_class WHERE relnamespace = <oid>`. Those OIDs must therefore be stable
across catalog-table queries and join-consistent, and `pg_catalog` must keep
its canonical namespace OID 11 (the static catalog rows reference it).

These three tests assert those invariants and currently fail on master:

* schema_oid_is_stable_across_pg_attribute_query
  A schema's OID drifts (e.g. 16385 -> 16457) after `pg_attribute` is
  queried, because pg_attribute replaces the shared OID cache with
  table-only entries, evicting the schema OID; the next pg_namespace
  re-assigns a different OID.

* pg_class_resolves_table_via_namespace_oid
  The concrete symptom: after the eviction above, filtering pg_class by an
  earlier-resolved namespace OID matches 0 rows, so no tables are listed.

* pg_catalog_namespace_keeps_fixed_oid_eleven
  pg_namespace assigns pg_catalog a generated OID (16385) instead of the
  fixed 11 that pg_type.typnamespace / pg_proc.pronamespace reference, so
  system-object -> namespace joins (e.g. resolving a column's data type)
  fail.

Verified: all three FAIL on master and PASS once OIDs are derived
deterministically (PR datafusion-contrib#391).
@sunng87 sunng87 closed this Jul 21, 2026
@sunng87
sunng87 deleted the test/pg-catalog-oid-stability branch July 21, 2026 15:07
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.

1 participant