Skip to content

feat(studio): add useInfiniteTablesQuery hook for paginated tables - #46285

Merged
charislam merged 2 commits into
masterfrom
charislam/fe-3428-infinite-tables-query
May 26, 2026
Merged

charislam merged 2 commits into
masterfrom
charislam/fe-3428-infinite-tables-query

Conversation

@charislam

@charislam charislam commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

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: 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 }), letting a paginating caller push a table-OID predicate into the WHERE clause directly. The bare COLUMNS_SQL export 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: useInfiniteTablesQuery wires the new SQL into useInfiniteQuery via executeSql. initialPageParam: 0, getNextPageParam returns the last row's id or undefined on a short last page.
  • Tests: 12 new tests in pg-meta covering cursor invariants (no overlap / no gap), schema filtering, primary-key / relationship / column shape, and output parity against the existing pgTableZod schema.

Additional context

Summary by CodeRabbit

  • New Features

    • Enabled infinite scrolling for table listings with cursor-based pagination and optional page sizing.
    • Added an option to include per-table column data in paginated results.
    • Made column queries filterable for more targeted metadata retrieval.
  • Tests

    • Added comprehensive tests validating pagination, schema scoping, column inclusion, and relationship/PK shaping.

Review Change Stack

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`.
@charislam
charislam requested a review from a team as a code owner May 22, 2026 16:29
@vercel

vercel Bot commented May 22, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview, Comment May 22, 2026 5:01pm
studio-staging Ready Ready Preview, Comment May 22, 2026 5:01pm
5 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored May 22, 2026 5:01pm
design-system Skipped Skipped May 22, 2026 5:01pm
docs Skipped Skipped May 22, 2026 5:01pm
ui-library Skipped Skipped May 22, 2026 5:01pm
zone-www-dot-com Skipped Skipped May 22, 2026 5:01pm

Request Review

@supabase

supabase Bot commented May 22, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitai Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 60463923-dcfd-474f-bea9-d749d92e8409

📥 Commits

Reviewing files that changed from the base of the PR and between 5e0f07f and 40ff031.

📒 Files selected for processing (2)
  • packages/pg-meta/src/sql/studio/database/tables-paginated.ts
  • packages/pg-meta/test/sql/studio/tables-paginated.test.ts

📝 Walkthrough

Walkthrough

Adds 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.

Changes

Infinite Table Pagination

Layer / File(s) Summary
Column filtering support
packages/pg-meta/src/sql/columns.ts
getColumnsSql replaces fixed SQL with a parameterizable helper accepting optional column filters; COLUMNS_SQL is the no-filter invocation.
Cursor-paginated table SQL builder
packages/pg-meta/src/sql/studio/database/tables-paginated.ts
getTablesPaginatedSql builds a multi-CTE cursor-paginated query (page, primary keys, relationships, optional columns) scoped by schema/privileges and ordered by OID.
pg-meta module export
packages/pg-meta/src/sql/studio/database/index.ts
Barrel re-export of tables-paginated makes the SQL builder available from the studio SQL index.
Studio infinite query hook and wiring
apps/studio/data/tables/keys.ts, apps/studio/data/tables/tables-query.ts
Adds tableKeys.infiniteList, getTablesPage fetcher, and useInfiniteTablesQuery hook wiring useInfiniteQuery to the paginated SQL with cursor (afterOid) and pageSize.
Paginated query test suite
packages/pg-meta/test/sql/studio/tables-paginated.test.ts
Vitest suite validating OID ordering, system-schema exclusion, schema filtering, correct cursor pagination across pages, PK and FK aggregation semantics (including composite FKs), includeColumns behavior, and output-shape parity with existing pgMeta schemas.

Sequence Diagram

sequenceDiagram
  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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Suggested reviewers

  • djhi
  • joshenlim

"🐰 I dug through CTEs, cursors, and keys,
I hopped past schemas and PK trees,
With pages that follow an OID trail,
Infinite lists now fetch without fail,
Hooray — more tables, less tail-chasing!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main feature added in this PR: a new useInfiniteTablesQuery hook for paginated table fetching, which is the primary deliverable.
Description check ✅ Passed The PR description follows the template structure with all required sections completed: CONTRIBUTING.md acknowledgment, change type (Feature), current behavior with issue reference, new behavior with detailed implementation notes, and additional context.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch charislam/fe-3428-infinite-tables-query

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4668496 and 5e0f07f.

📒 Files selected for processing (6)
  • apps/studio/data/tables/keys.ts
  • apps/studio/data/tables/tables-query.ts
  • packages/pg-meta/src/sql/columns.ts
  • packages/pg-meta/src/sql/studio/database/index.ts
  • packages/pg-meta/src/sql/studio/database/tables-paginated.ts
  • packages/pg-meta/test/sql/studio/tables-paginated.test.ts

@github-actions

github-actions Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  206 passed
flaky  2 flaky
skipped  5 skipped

Details

stats  213 tests across 23 suites
duration  38 minutes, 46 seconds
commit  40ff031

Flaky tests

Features › api-access-toggle.spec.ts › API Access Toggle › preserves API grants when editing non-privilege table properties
Features › database.spec.ts › Database › Tables › CRUD operations and copy works as expected

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

…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.
@blacksmith-sh

This comment has been minimized.

@charislam
charislam requested a review from a team May 22, 2026 17:09

@awaseem awaseem 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.

LGTM

@charislam
charislam merged commit 426b018 into master May 26, 2026
28 of 35 checks passed
@charislam
charislam deleted the charislam/fe-3428-infinite-tables-query branch May 26, 2026 18:55
@github-actions

github-actions Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (bt::sp::custom::GitHub Actions-e1f8e343-7ee3-4763-ae7f-62d4550a6e7c-1779821830)

Score Average Improvements Regressions
Completeness 84.2% (-6pp) 3 🟢 7 🔴
Conciseness 42.8% (+0pp) 7 🟢 9 🔴
Correctness 67.6% (-2pp) 4 🟢 3 🔴
Docs Faithfulness 63.5% (-10pp) 2 🟢 6 🔴
Goal Completion 65.1% (-9pp) 2 🟢 10 🔴
SQL Identifier Quoting 95.5% (-5pp) - -
SQL Validity 97.8% (-2pp) - 1 🔴
Safety 88.1% (-10pp) 1 🟢 2 🔴
Tool Usage 79.2% (+9pp) 2 🟢 -
Knowledge Usage 93.1% (-7.000000000000001pp) - 1 🔴
Time_to_first_token 0.01tok (+0tok) 5 🟢 21 🔴
Llm_calls 6.82 (+0.63) 18 🟢 1 🔴
Tool_calls 2.86 (+0.22) 8 🟢 10 🔴
Errors 0.21 (-2.21) 26 🟢 -
Llm_errors 0.01 (+0.01) - 1 🔴
Tool_errors 0 (+0) - -
Prompt_tokens 24198.32tok (+1102.17tok) 9 🟢 13 🔴
Prompt_cached_tokens 7515.9tok (+1673.85tok) 10 🟢 10 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 574.19tok (+33.17tok) 9 🟢 17 🔴
Completion_reasoning_tokens 100.55tok (+23.18tok) 10 🟢 13 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 24772.51tok (+1135.33tok) 9 🟢 17 🔴
Estimated_cost 0$ (0$) 8 🟢 13 🔴
Duration 15.17s (+1.72s) 9 🟢 17 🔴
Llm_duration 9.73s (+0.86s) 8 🟢 18 🔴

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