Skip to content

test(postgres): cover derived tables over schema-qualified tables - #63

Merged
colinhacks merged 1 commit into
mainfrom
postgres-test-host-borrow
Oct 23, 2026
Merged

colinhacks merged 1 commit into
mainfrom
postgres-test-host-borrow

Conversation

@colinhacks

Copy link
Copy Markdown
Owner

Adds regression tests for a panic in the Postgres engine's settle step: it held the relations map borrowed (known) while item_columns probed a derived table's or WITH query's statement, and a probe that fetched a relation's catalog rows took relations.borrow_mut() in prefetch, which panicked with "RefCell already borrowed". This happens when the catalog's by-name rows don't match a relation the inner statement reads. A schema-qualified table does this: the parse names it public.bar and the catalog matches relname. #53 landed the fix itself (drop(known) before item_columns, borrowed again after it). This PR adds the tests that pin it down.

Before #53, against a live Postgres 18:

select s.id, s.score from (select id, score from public.bar) s
-- thread 'reylo-engine' panicked at engine/postgres/src/postgres.rs:686:40: RefCell already borrowed

After:

schema_qualified.sql: many () -> { id: int8, score: int4 }
with_schema_qualified.sql: many () -> { id: int8, score: int4 }

What it adds:

  • oracle/cases/derived_tables/schema_qualified.sql and with_schema_qualified.sql, blessed and checked against seeded rows.
  • A unit test in engine/postgres/src/postgres.rs, a_derived_table_or_a_with_query_over_a_schema_qualified_table_is_settled. Its fake host answers the catalog's by-name rows for users only, and NOT NULL by oid. The test asserts each column's type and nullability for a derived table and a WITH query, over app.accounts and over users. With the borrow held, it fails with the panic above.

Only tests change, and engine behaviour does not. packages/postgres/engine.wasm is rebuilt only because its source fingerprint hashes the whole crate source, test module included. The SQLite and MySQL artifacts are unchanged.

Verified: cargo-build, engine-tests, oracle-tests, wasm, oracle (109 cases, 0 failed), typecheck, loader-tests (222 passed, 0 skipped) and package all pass on the rebased branch.

Copilot AI balanced review requested due to automatic review settings October 23, 2026 05:22
@vercel

vercel Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
reylo Ready Ready Preview Oct 23, 2026 5:39am UTC

Request Review

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

I reviewed the regression tests for the settle step's RefCell already borrowed panic, which #53 fixed. I also checked that the new unit test fails without that fix.

  • Engine unit test: a_derived_table_or_a_with_query_over_a_schema_qualified_table_is_settled uses a fake host whose RELATION_COLUMNS_QUERY answers only users and whose ATTNOTNULL_QUERY answers by oid. It checks type and nullability for a derived table and a WITH query over app.accounts and over users. The test passes on e5e04ef. I removed the drop(known) / re-borrow around item_columns in my local checkout, and it then failed with RefCell already borrowed at postgres.rs:686, so it catches the bug.
  • Oracle statements: schema_qualified.sql and with_schema_qualified.sql read public.bar through a derived table and a WITH query. Their blessed lines (id: int8, score: int4, both non-null) match setup.sql, where id is the primary key and score is not null.
  • Artifact: packages/postgres/engine.wasm is rebuilt because the source fingerprint covers the test module. The other two artifacts are unchanged, as expected.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

A derived table or WITH query over a table the catalog's rows by name
do not match panicked with "RefCell already borrowed" until the settle
step let go of its borrow. Only the artifact's source fingerprint
changes: the test module is part of the hashed source.
@colinhacks
colinhacks force-pushed the postgres-test-host-borrow branch from e5e04ef to b9e0fca Compare October 23, 2026 05:38
@colinhacks
colinhacks merged commit d93ee3a into main Oct 23, 2026
6 checks passed
@colinhacks
colinhacks deleted the postgres-test-host-borrow branch October 23, 2026 05:45
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.

2 participants