Skip to content

Commit d0abf3e

Browse files
perf(tables): tenant-bound upsert conflict lookup
Same unestimatable data->>key predicate as the unique checks; an insert-path upsert has no existing match so the lookup can't exit early and seq-scans the whole shared relation. The upsert already runs in a transaction — set the planner flag on it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 2f44ac0 commit d0abf3e

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

apps/sim/lib/table/service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,6 +2511,10 @@ export async function upsertRow(
25112511
// trigger (migration 0198). The update path doesn't change row_count, so no check needed.
25122512
const result = await db.transaction(async (trx) => {
25132513
await setTableTxTimeouts(trx)
2514+
// The conflict lookups below match on `data->>key` — unestimatable, and an
2515+
// insert-path upsert (no existing match) can't exit early, so the planner
2516+
// would seq-scan the whole shared relation. See withSeqscanOff.
2517+
await trx.execute(sql`SET LOCAL enable_seqscan = off`)
25142518

25152519
// Find existing row by single conflict target column
25162520
const [existingRow] = await trx

0 commit comments

Comments
 (0)