Commit 2cecb21
authored
improvement(tables): cut the DB round trips a table read and write spend on protocol (#8104)
* improvement(tables): cut the DB round trips a table read and write spend on protocol
The grid's first page spent more time on round trips than on work. Four of them
were avoidable:
- `pendingDeleteMask` probed `table_jobs` on every read, though the table a
request just loaded already carries its latest non-export job, and the
`one_active_per_table` unique index makes that row the running delete when one
exists. Callers that hold a table across a long walk (the export stream, the
snapshot builder) keep probing per page, so a delete starting mid-walk still
begins masking.
- The run-state sidecar was read for every table, including the ones that
declare no workflow group and therefore cannot have a row — four chunked
queries on a 1000-row page, all returning nothing.
- The drain opened a transaction per batch. The guards are fixed for the call,
so each extra batch paid `BEGIN` + `set_config` + `COMMIT` for nothing.
- `setTableTxTimeouts` issued three `SET LOCAL` statements; `set_config(…, true)`
is the same thing and fits in one round trip, as the read guards already do.
A 1000-row page goes from 22 statements to 14, a 50-row page from 15 to 13, and
every write transaction drops two.
* review(tables): drop the delete-mask elision and correct the provenance snapshot doc
Reading the delete job from the table a request already loaded widened a race
the mask probe has always had — a job committing between the check and the row
read is missed either way, but trusting the loaded fields moves the check two
queries earlier. Closing it properly means evaluating the job inside the row
read's own snapshot, which is a larger change than this one, so the elision is
removed and `pending-delete-mask.ts` is back to what it was.
The three remaining reductions are untouched: they were the bulk of the win,
and each is a read this code cannot need rather than a read it takes on faith.
Also updates `TableRowProvenanceReader`'s doc, which still described one
repeatable-read transaction per batch.1 parent acc6cbd commit 2cecb21
7 files changed
Lines changed: 252 additions & 90 deletions
File tree
- apps/sim/lib/table
- __tests__
- rows
Lines changed: 39 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| |||
666 | 668 | | |
667 | 669 | | |
668 | 670 | | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
71 | 96 | | |
72 | 97 | | |
73 | 98 | | |
| |||
420 | 445 | | |
421 | 446 | | |
422 | 447 | | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
428 | 451 | | |
429 | 452 | | |
430 | 453 | | |
| |||
436 | 459 | | |
437 | 460 | | |
438 | 461 | | |
439 | | - | |
| 462 | + | |
440 | 463 | | |
441 | 464 | | |
442 | 465 | | |
| |||
450 | 473 | | |
451 | 474 | | |
452 | 475 | | |
453 | | - | |
| 476 | + | |
454 | 477 | | |
455 | 478 | | |
456 | 479 | | |
| |||
459 | 482 | | |
460 | 483 | | |
461 | 484 | | |
462 | | - | |
| 485 | + | |
463 | 486 | | |
464 | 487 | | |
465 | 488 | | |
| |||
472 | 495 | | |
473 | 496 | | |
474 | 497 | | |
475 | | - | |
| 498 | + | |
476 | 499 | | |
477 | 500 | | |
478 | 501 | | |
| |||
491 | 514 | | |
492 | 515 | | |
493 | 516 | | |
494 | | - | |
| 517 | + | |
495 | 518 | | |
496 | 519 | | |
497 | 520 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
| |||
258 | 262 | | |
259 | 263 | | |
260 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
43 | 61 | | |
44 | 62 | | |
45 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
959 | 959 | | |
960 | 960 | | |
961 | 961 | | |
962 | | - | |
963 | | - | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
964 | 966 | | |
965 | 967 | | |
966 | 968 | | |
| |||
0 commit comments