Repository navigation
feat(studio): add useInfiniteTablesQuery hook for paginated tables - #46285
Conversation
Adds a cursor-paginated tables query for use in the Schema Designer and
Database > Tables list — both currently fetch the entire schema in one
shot via useTablesQuery, which hangs the page at 400+ tables. No callers
are switched over in this commit; that's the next PR.
- `pg-meta`: new `getTablesPaginatedSql` SQL builder that picks a page of
table OIDs first (cheap pg_class index scan) and constrains every
enrichment CTE (primary keys, relationships, columns) to that set.
Pagination is by `c.oid > $afterOid` rather than OFFSET, so deep pages
stay O(limit). Relationships use a UNION ALL keyed by table_id so the
downstream join is a plain equi-join.
- `pg-meta`: `COLUMNS_SQL` is now produced by `getColumnsSql({ filter })`,
which lets a paginating caller push a table-OID predicate into the
WHERE clause instead of wrapping the query externally. The bare
`COLUMNS_SQL` export is preserved for the 5 existing callers.
- `studio`: `useInfiniteTablesQuery` wires the new SQL into
`useInfiniteQuery` via `executeSql`. `initialPageParam` is 0 and
`getNextPageParam` returns the last row's id, or undefined on a
short last page.
- Tests: 12 new tests in `pg-meta` covering cursor invariants, schema
filtering, primary-key / relationship / column shape, and output
parity against `pgTableZod`.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdds OID cursor-based, infinite-scroll table listing: a paginated SQL builder with optional column inclusion, pg-meta exports, a Studio infinite-query hook and fetcher, and comprehensive Vitest coverage validating pagination and metadata shaping. ChangesInfinite Table Pagination
Sequence DiagramsequenceDiagram
participant Studio
participant Hook as useInfiniteTablesQuery
participant Query as useInfiniteQuery
participant Fetch as getTablesPage
participant SQL as getTablesPaginatedSql
participant DB as Database
Studio->>Hook: render with projectRef
Hook->>Query: initialize with tableKeys.infiniteList
Query->>Fetch: fetch page with pageParam (afterOid)
Fetch->>SQL: build paginated SQL (limit, afterOid)
Fetch->>DB: executeSql(paginatedSQL)
DB-->>Fetch: rows (SafePostgresTable[])
Fetch-->>Query: return page
Query->>Query: compute getNextPageParam (last row id or undefined)
Query-->>Hook: accumulated pages
Hook-->>Studio: infinite list data ready
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/pg-meta/src/sql/studio/database/tables-paginated.ts`:
- Around line 115-118: The join currently matches c.conkey and c.confkey
independently with ANY(...), producing cross-products for composite FKs; change
the join logic to unnest c.conkey and c.confkey WITH ORDINALITY (or use
generate_subscripts) so you can join the source and target arrays by their
ordinality/index and then join those values to pg_attribute; update the joins
involving aliases c, sa, ta (and the corresponding mirrored block at the other
occurrence) to use the paired unnest approach so sa.attnum matches the unnested
source element and ta.attnum matches the unnested target element for the same
ordinal.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 9da18e4a-fdec-4237-a62f-a3fe0df6c5b0
📒 Files selected for processing (6)
apps/studio/data/tables/keys.tsapps/studio/data/tables/tables-query.tspackages/pg-meta/src/sql/columns.tspackages/pg-meta/src/sql/studio/database/index.tspackages/pg-meta/src/sql/studio/database/tables-paginated.tspackages/pg-meta/test/sql/studio/tables-paginated.test.ts
🎭 Playwright Test ResultsDetails
Flaky testsFeatures › api-access-toggle.spec.ts › API Access Toggle › preserves API grants when editing non-privilege table properties Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
…s query The relationships CTE matched conkey and confkey independently with ANY(...), producing an N*N cross-product of source/target columns for composite foreign keys. Use lateral unnest(conkey, confkey) so each source attnum is paired with its corresponding target attnum.
This comment has been minimized.
This comment has been minimized.
Braintrust eval reportAssistant (bt::sp::custom::GitHub Actions-e1f8e343-7ee3-4763-ae7f-62d4550a6e7c-1779821830)
|
I have read the CONTRIBUTING.md file.
YES
What kind of change does this PR introduce?
Feature — adds a new data-layer hook. No callers are switched over in this PR.
What is the current behavior?
The Schema Designer and Database > Tables list both call
useTablesQuery({ includeColumns: true }), which fetches the full schema (every table, with every column, every relationship) in one round-trip. For customers with many tables this never loads. Towards FE-3428.What is the new behavior?
Introduces
useInfiniteTablesQuery— a cursor-paginated tables hook ready to be consumed by the two pages above in follow-up PRs.pg-meta: newgetTablesPaginatedSqlSQL builder that picks a page of table OIDs first (cheappg_classindex scan) and constrains every enrichment CTE (primary keys, relationships, columns) to that set. Pagination is byc.oid > $afterOidrather thanOFFSET, so deep pages stay O(limit). Relationships use aUNION ALLkeyed bytable_idso the downstream join is a plain equi-join.pg-meta:COLUMNS_SQLis now produced bygetColumnsSql({ filter }), letting a paginating caller push a table-OID predicate into the WHERE clause directly. The bareCOLUMNS_SQLexport is preserved for the 5 existing callers (pg-meta-columns,pg-meta-tables,pg-meta-views,pg-meta-materialized-views,pg-meta-foreign-tables).studio:useInfiniteTablesQuerywires the new SQL intouseInfiniteQueryviaexecuteSql.initialPageParam: 0,getNextPageParamreturns the last row'sidorundefinedon a short last page.pg-metacovering cursor invariants (no overlap / no gap), schema filtering, primary-key / relationship / column shape, and output parity against the existingpgTableZodschema.Additional context
Summary by CodeRabbit
New Features
Tests