Optimize __rts_btree_row_modify and __rts_btree_col_modify to skip redundant B-tree search

XMLWordPrintableJSON

    • Storage Engines - Transactions
    • 555.773
    • SE Transactions - 2026-06-05, SE Transactions - 2026-06-19
    • 1

      Problem

      Both RTS helpers open a fresh WT_CURSOR_BTREE, call a search function to locate the row/record, then apply the update — even though the caller already holds the exact page and slot:

      • _rts_btree_row_modify (src/rollback_to_stable/rts_btree.c:274) calls _wt_row_search with the key, but both call sites (lines 629, 836) already hold WT_REF *ref and WT_ROW *rip — the exact page and row slot.
      • _rts_btree_col_modify (src/rollback_to_stable/rts_btree.c:244) calls wt_col_search with the recno, but the column-store iteration loop at line 860 already holds WT_COL *cip (and thus the slot via WT_COL_SLOT(page, cip)) before dispatching to _rts_btree_abort_ondisk_kv.

      In both cases the search is redundant: the position is already known before the function is called.

      Proposed Optimization

      Thread the known slot pointer into each helper (or position the cursor directly) instead of searching:

      Row store — pass WT_ROW *rip and set the cursor position directly:

      cbt.ref     = ref;
      cbt.slot    = WT_ROW_SLOT(ref->page, rip);
      cbt.compare = 0;
      cbt.ins     = NULL;
      

      Column store — pass WT_COL *cip down through __rts_btree_abort_ondisk_kv and set:

      cbt.ref     = ref;
      cbt.slot    = WT_COL_SLOT(ref->page, cip);
      cbt.compare = 0;
      cbt.ins     = NULL;
      

      This lets _wt_row_modify / _wt_col_modify take the existing-slot update path (cbt->compare == 0, cbt->ins == NULL) without any tree traversal or binary search.

      Impact

      RTS iterates over every key on every dirty page during startup recovery and prepared-transaction rollback. Each call to these helpers currently performs a redundant B-tree search even though the caller already has the slot. Eliminating both searches reduces CPU overhead on the critical recovery path.

      Acceptance Criteria

      • _rts_btree_row_modify no longer calls _wt_row_search when rip is available
      • _rts_btree_col_modify no longer calls _wt_col_search when cip is available
      • Existing RTS csuite / Python suite tests continue to pass

            Assignee:
            Haribabu Kommi
            Reporter:
            Chenhao Qu
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: