diff --git a/README.md b/README.md index 0e09827..82f620f 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,10 @@ packages/ # Install dependencies pnpm install +# Login to wrangler (needed to parse SQL w/ AI) +# Or set a CLOUDFLARE_API_TOKEN in the projects .env file +wrangler login + # Run locally pnpm dev diff --git a/packages/big-daddy/llm-resources/conductor-crud.md b/packages/big-daddy/llm-resources/conductor-crud.md index a7e3338..768be79 100644 --- a/packages/big-daddy/llm-resources/conductor-crud.md +++ b/packages/big-daddy/llm-resources/conductor-crud.md @@ -20,12 +20,14 @@ 4. Execute per-shard INSERTs with remapped parameters 5. Dispatch index maintenance events 6. Invalidate cache +7. **Bump per-shard row counts via `batchBumpTableShardRowCounts()`** **Key Functions:** - `groupInsertByShards()` - Groups rows by target shard, remaps placeholder indices -- `extractInsertedRows()` - Builds row data for index maintenance -**Important:** Multi-row INSERTs are split by shard key hash. +**Important:** +- Multi-row INSERTs are split by shard key hash +- Row counts use VALUES.length (not SQLite's rowsWritten which includes index writes) --- @@ -50,6 +52,7 @@ 4. Execute on shards 5. Dispatch index maintenance with old rows 6. Invalidate cache +7. **Decrement per-shard row counts via `batchBumpTableShardRowCounts()`** --- diff --git a/packages/big-daddy/llm-resources/conductor-key-patterns.md b/packages/big-daddy/llm-resources/conductor-key-patterns.md index 2604f2a..448f0d6 100644 --- a/packages/big-daddy/llm-resources/conductor-key-patterns.md +++ b/packages/big-daddy/llm-resources/conductor-key-patterns.md @@ -28,6 +28,26 @@ Every table has a hidden `_virtualShard` column: - INSERT: Specific key invalidation - UPDATE/DELETE: Full index invalidation (conservative) +## Per-Shard Row Count Tracking + +Row counts are tracked per-shard in `table_shards.row_count`: + +| Operation | Action | +|-----------|--------| +| INSERT | Increment by VALUES.length per shard | +| DELETE | Decrement by rowsAffected per shard | +| UPDATE | No change (row count unchanged) | +| Resharding | Set exact counts after atomic switch | + +**Why VALUES.length for INSERT?** +SQLite's `rowsWritten` counts B-tree operations (table + indexes), which inflates the count 2x for tables with composite primary keys. Using VALUES.length gives the logical row count. + +**Topology Methods:** +- `getTableShardRowCounts(table)` → get all shard counts +- `bumpTableShardRowCount(table, shard, delta)` → single shard +- `batchBumpTableShardRowCounts(table, deltaMap)` → multiple shards +- `setTableShardRowCounts(table, countsMap)` → set exact (resharding) + ## Effect Usage Table operations (`create-drop.ts`) use Effect for: - Typed errors (`TableAlreadyExistsError`, `TopologyFetchError`, etc.) diff --git a/packages/big-daddy/src/dashboard/database.tsx b/packages/big-daddy/src/dashboard/database.tsx index 6b8fd82..ba27a11 100644 --- a/packages/big-daddy/src/dashboard/database.tsx +++ b/packages/big-daddy/src/dashboard/database.tsx @@ -38,6 +38,7 @@ export const DashboardPage = ({