Skip to content

D1 tables: chunk row counts at celld UNION limit - #108

Merged
ryuzdev merged 1 commit into
mainfrom
d1-count-chunks
Oct 28, 2026
Merged

ryuzdev merged 1 commit into
mainfrom
d1-count-chunks

Conversation

@ryuzdev

@ryuzdev ryuzdev commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

User report (2026-10-28): D1 preview 502s on pacjent-crm (/console?app=pacjent-crm&t=d1).

Root cause, reproduced live against prod celld 0.6.2: celld d1 execute refuses 6+ UNION ALL terms (D1_EXEC_ERROR: too many terms in compound SELECT; without a trailing semicolon the message misleadingly says "incomplete statement"). The D1 tables view runs one SELECT … UNION ALL … over every visible table, so any app with 6+ visible tables 502s. pacjent-crm has 7 (photos, task, credential, patient, account, session, challenge) since its 4th migration. Verified term count, not content: 5 pure-constant unions pass, 6+ fail regardless of tables.

Fix: MAX_UNION_TERMS = 5; table_count_queries chunks the table list; list_tables runs one exec per chunk and merges counts. build_table_counts asserts its input fits one exec so the next person to reuse it chunks first.

Live on prod (outer:e49693f, throwaway account, deleted after): the exact 7-table counts query fails as one exec; the 5+2 chunked execs both succeed.

Tests: new table_counts_chunk_at_the_celld_union_limit (0/1/5/7 tables, per-exec term cap, every table counted once); full suite 1103 + 7 green. No migration.

Summary by CodeRabbit

  • Bug Fixes
    • Table row counts now load more reliably for databases with many tables. Counts are gathered in smaller batches and combined, so larger table lists can be counted without relying on a single query to handle every table. The displayed counts continue to cover all tables across the database.

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9fa363d0-577f-46c8-a19b-8227f39de4fa
Commits

Reviewing files that changed from the base of the PR and between 7a0f2c6 and e49693f.

Files selected for processing: 1
  • crates/outer/src/http/console_data/d1.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Table-count queries now contain no more than five tables. list_tables executes the generated queries and accumulates their counts.

Changes: Table count query flow

Layer / File(s) Summary
Query size limit and chunking
crates/outer/src/http/console_data/d1.rs
build_table_counts rejects inputs with more than five tables. table_count_queries builds queries for chunks of up to five tables.
Execute chunks and test boundaries
crates/outer/src/http/console_data/d1.rs
list_tables executes each generated query. The documentation describes multiple queries, and tests cover empty input, chunk boundaries, query sizes, table order, and coverage.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: Minimal · up to e4969

The chunked table-count implementation appears mergeable with no identified behavior or availability risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: chunking D1 table row-count queries at the celld UNION limit.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 1 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@ryuzdev
ryuzdev merged commit 6fb6ee4 into main Oct 28, 2026
5 checks passed
@ryuzdev
ryuzdev deleted the d1-count-chunks branch October 28, 2026 14:35
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