8000 feat(postgres): pin subqueries, with queries and views by their keys by colinhacks · Pull Request #105 · colinhacks/reylo · GitHub
[go: up one dir, main page]

Skip to content

feat(postgres): pin subqueries, with queries and views by their keys - #105

Merged
colinhacks merged 7 commits into
mainfrom
keys-through-subqueries
Oct 24, 2026
Merged

colinhacks merged 7 commits into
mainfrom
keys-through-subqueries

Conversation

@colinhacks
Copy link
Copy Markdown
Owner

A subquery, a WITH query or a view is now pinned to one row by a unique key of its rows, as a table is by its index. select * from (select id, title from posts) s where s.id = :id was many and is now maybeOne, and so are the WITH and view forms.

The rule

A set of a subquery's output columns is a key of its rows when either:

  • one of its FROM items has a unique key the select list keeps unchanged, and every other item is pinned to one row per row of that item (the closure the proof already computes, seeded with that item); or
  • its GROUP BY (no grouping sets) or its DISTINCT / DISTINCT ON names those columns.

The outer WHERE and ON equalities then pin the subquery by that key under the same checks a table's key gets: a value or a pinned item's column, nothing volatile, no COLLATE, and a type the key's equality compares without converting it.

Nothing that can repeat a row gives a key: a set operation, VALUES, a set-returning call at that level, grouping sets, a key column passed through an expression or a cast, a join to a table that is not pinned, a FULL JOIN, a recursive WITH. A LATERAL subquery may be pinned by its key, but it is never the source of a key for the FROM around it, since its rows are computed anew for each outer row.

Views

The analysis already reads each view's definition. The proof now reads it as a subquery, with the keys, column types and functions of the tables it reads, which are asked in one more catalog round only for a statement that reads a view. A view's statement sees none of the reading statement's WITH queries.

Checks

  • oracle/cases/subquery_keys: 52 statements, 30 maybeOne and 22 refusals, run over seeded edge values with no contradiction.
  • The whole oracle passes with --strict-coverage. One existing answer moves, json_schema_checks/view.sql, a view read by its key: many to maybeOne.
  • Two unit tests that asserted the old refusal for select x.title from (select * from posts) x where x.id = $1 now infer maybeOne; a new unit test covers the rule and its refusals.
  • nub run test with both test databases: 251 pass, none skipped. The docs state the rule in the Postgres page's cardinality section, with a captured example.

Copilot AI balanced review requested due to automatic review settings October 24, 2026 00:57
@pullfrog
pullfrog Bot commented Oct 24, 2026 •
Copy link
Copy Markdown
Contributor

No configured credential can serve this run. Your Claude Pro/Max subscription has hit its usage limit, which resets at 2026-10-26 08:00 UTC. Re-trigger after it resets, or add an API key for this provider, which Pullfrog falls back to automatically.

The providers' responses
CLAUDE_CODE_OAUTH_TOKEN: 429: This request would exceed your account's rate limit. Please try again later.

Pick another model →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using claude-opus-5-5

@vercel
vercel Bot commented Oct 24, 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 24, 2026 1:31am 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 insufficient remaining quota.

@pullfrog
pullfrog Bot commented Oct 24, 2026
Copy link
Copy Markdown
Contributor

No configured credential can serve this run. Your Claude Pro/Max subscription has hit its usage limit, which resets at 2026-10-26 08:00 UTC. Re-trigger after it resets, or add an API key for this provider, which Pullfrog falls back to automatically.

The providers' responses
CLAUDE_CODE_OAUTH_TOKEN: 429: This request would exceed your account's rate limit. Please try again later.

Pick another model →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using claude-opus-5-5

@colinhacks
colinhacks force-pushed the keys-through-subqueries branch from f62d796 to 6133e41 Compare October 24, 2026 01:30
@pullfrog
pullfrog Bot commented Oct 24, 2026
Copy link
Copy Markdown
Contributor

No configured credential can serve this run. Your Claude Pro/Max subscription has hit its usage limit, which resets at 2026-10-26 08:00 UTC. Re-trigger after it resets, or add an API key for this provider, which Pullfrog falls back to automatically.

The providers' responses
CLAUDE_CODE_OAUTH_TOKEN: 429: This request would exceed your account's rate limit. Please try again later.

Pick another model →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using claude-opus-5-5

@colinhacks
colinhacks merged commit ea0f99e into main Oct 24, 2026
6 of 7 checks passed
@colinhacks
colinhacks deleted the keys-through-subqueries branch October 24, 2026 01:39
colinhacks added a commit that referenced this pull request Oct 26, 2026
A host that runs the row-count proof itself asks catalog() for the
relations a statement reads. Views among them came with no defining
statement and none of the keys of the tables they read, so a read by key
through a view was never pinned, as an analysis pins it since #105.
colinhacks added a commit that referenced this pull request Oct 26, 2026
* fix(postgres): give a host's row-count catalog its views' keys

A host that runs the row-count proof itself asks catalog() for the
relations a statement reads. Views among them came with no defining
statement and none of the keys of the tables they read, so a read by key
through a view was never pinned, as an analysis pins it since #105.

* fix(postgres): know every view a statement reads before settling

viewed dropped each prefetch it issued, and which list a relation was
asked in turned on how many views were known yet, so a round could
settle with a view over a view still unread: a read by key through it
went unpinned. It now answers only once every prefetch is answered.
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

0