Optimize __time_window_clear_obsolete to check stop time point first

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Gone away
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Btree
    • None
    • Storage Engines - Transactions
    • 787.046
    • SE Transactions - 2026-08-14
    • 2

      Background

      __time_window_clear_obsolete (src/btree/bt_page.c) currently checks start visibility before stop visibility:

      if (__wt_txn_tw_start_visible_all(session, tw)) {
          tw->start_ts = tw->durable_start_ts = WT_TS_NONE;
          tw->start_txn = WT_TXN_NONE;
      }
      
      if (__wt_txn_tw_stop_visible_all(session, tw)) {
          tw->stop_ts = tw->durable_stop_ts = WT_TS_NONE;
          tw->stop_txn = WT_TXN_NONE;
      }
      

      Optimization

      Check the stop time point first. If the stop is globally visible, the start must also be globally visible (a value cannot be deleted before it is written), so we can clear the entire time window without a separate start visibility check:

      if (__wt_txn_tw_stop_visible_all(session, tw)) {
          tw->stop_ts = tw->durable_stop_ts = WT_TS_NONE;
          tw->stop_txn = WT_TXN_NONE;
          /* Stop visible to all implies start is also visible to all. */
          tw->start_ts = tw->durable_start_ts = WT_TS_NONE;
          tw->start_txn = WT_TXN_NONE;
          return;
      }
      
      if (__wt_txn_tw_start_visible_all(session, tw)) {
          tw->start_ts = tw->durable_start_ts = WT_TS_NONE;
          tw->start_txn = WT_TXN_NONE;
      }
      

      Benefit

      Avoids one redundant visibility check (__wt_txn_tw_start_visible_all) in the common case where the stop is globally visible. The function is called for every cell during page reconciliation, so the saving compounds across workloads with many deleted values.

            Assignee:
            Chenhao Qu
            Reporter:
            Chenhao Qu
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: