@@ -1495,11 +1495,13 @@ impl Inner {
14951495 // The current transaction has modified this table, and the table is indexed.
14961496 let tx_state = self . tx_state . as_ref ( ) . unwrap ( ) ;
14971497 Ok ( IterByColRange :: Index ( IndexSeekIterInner {
1498+ ctx,
14981499 table_id : * table_id,
14991500 tx_state,
15001501 inserted_rows,
15011502 committed_rows : self . committed_state . index_seek ( table_id, & cols, & range) ,
15021503 committed_state : & self . committed_state ,
1504+ num_committed_rows_fetched : 0 ,
15031505 } ) )
15041506 } else {
15051507 // Either the current transaction has not modified this table, or the table is not
@@ -1513,10 +1515,12 @@ impl Inner {
15131515 scan_iter : self . iter ( ctx, table_id) ?,
15141516 } ) ) ,
15151517 Some ( tx_state) => Ok ( IterByColRange :: CommittedIndex ( CommittedIndexIter {
1518+ ctx,
15161519 table_id : * table_id,
15171520 tx_state,
15181521 committed_state : & self . committed_state ,
15191522 committed_rows,
1523+ num_committed_rows_fetched : 0 ,
15201524 } ) ) ,
15211525 } ,
15221526 None => Ok ( IterByColRange :: Scan ( ScanIterByColRange {
@@ -1689,7 +1693,7 @@ pub struct Iter<'a> {
16891693 table_id : TableId ,
16901694 inner : & ' a Inner ,
16911695 stage : ScanStage < ' a > ,
1692- committed_rows_fetched : u64 ,
1696+ num_committed_rows_fetched : u64 ,
16931697}
16941698
16951699impl Drop for Iter < ' _ > {
@@ -1702,7 +1706,7 @@ impl Drop for Iter<'_> {
17021706 self . ctx . reducer_name ( ) . unwrap_or_default ( ) ,
17031707 & self . table_id . into ( ) ,
17041708 )
1705- . inc_by ( self . committed_rows_fetched ) ;
1709+ . inc_by ( self . num_committed_rows_fetched ) ;
17061710 }
17071711}
17081712
@@ -1713,7 +1717,7 @@ impl<'a> Iter<'a> {
17131717 table_id,
17141718 inner,
17151719 stage : ScanStage :: Start ,
1716- committed_rows_fetched : 0 ,
1720+ num_committed_rows_fetched : 0 ,
17171721 }
17181722 }
17191723}
@@ -1771,7 +1775,7 @@ impl<'a> Iterator for Iter<'a> {
17711775 let _span = tracing:: debug_span!( "ScanStage::Committed" ) . entered ( ) ;
17721776 for ( row_id, row) in iter {
17731777 // Increment metric for number of committed rows scanned.
1774- self . committed_rows_fetched += 1 ;
1778+ self . num_committed_rows_fetched += 1 ;
17751779 // Check the committed row's state in the current tx.
17761780 match self . inner . tx_state . as_ref ( ) . map ( |tx_state| tx_state. get_row_op ( & table_id, row_id) ) {
17771781 Some ( RowState :: Committed ( _) ) => unreachable ! ( "a row cannot be committed in a tx state" ) ,
@@ -1802,11 +1806,50 @@ impl<'a> Iterator for Iter<'a> {
18021806}
18031807
18041808pub struct IndexSeekIterInner < ' a > {
1809+ ctx : & ' a ExecutionContext < ' a > ,
18051810 table_id : TableId ,
18061811 tx_state : & ' a TxState ,
18071812 committed_state : & ' a CommittedState ,
18081813 inserted_rows : BTreeIndexRangeIter < ' a > ,
18091814 committed_rows : Option < BTreeIndexRangeIter < ' a > > ,
1815+ num_committed_rows_fetched : u64 ,
1816+ }
1817+
1818+ impl Drop for IndexSeekIterInner < ' _ > {
1819+ fn drop ( & mut self ) {
1820+ // Increment number of index seeks
1821+ DB_METRICS
1822+ . rdb_num_index_seeks
1823+ . with_label_values (
1824+ & self . ctx . txn_type ( ) ,
1825+ & self . ctx . database ( ) ,
1826+ self . ctx . reducer_name ( ) . unwrap_or_default ( ) ,
1827+ & self . table_id . 0 ,
1828+ )
1829+ . inc ( ) ;
1830+
1831+ // Increment number of index keys scanned
1832+ DB_METRICS
1833+ . rdb_num_keys_scanned
1834+ . with_label_values (
1835+ & self . ctx . txn_type ( ) ,
1836+ & self . ctx . database ( ) ,
1837+ self . ctx . reducer_name ( ) . unwrap_or_default ( ) ,
1838+ & self . table_id . 0 ,
1839+ )
1840+ . inc_by ( self . committed_rows . as_ref ( ) . map_or ( 0 , |iter| iter. keys_scanned ( ) ) ) ;
1841+
1842+ // Increment number of rows fetched
1843+ DB_METRICS
1844+ . rdb_num_rows_fetched
1845+ . with_label_values (
1846+ & self . ctx . txn_type ( ) ,
1847+ & self . ctx . database ( ) ,
1848+ self . ctx . reducer_name ( ) . unwrap_or_default ( ) ,
1849+ & self . table_id . 0 ,
1850+ )
1851+ . inc_by ( self . num_committed_rows_fetched ) ;
1852+ }
18101853}
18111854
18121855impl < ' a > Iterator for IndexSeekIterInner < ' a > {
@@ -1830,6 +1873,7 @@ impl<'a> Iterator for IndexSeekIterInner<'a> {
18301873 . map_or ( false , |table| table. contains ( row_id) )
18311874 } )
18321875 } ) {
1876+ self . num_committed_rows_fetched += 1 ;
18331877 return Some ( get_committed_row ( self . committed_state , & self . table_id , row_id) ) ;
18341878 }
18351879
@@ -1838,10 +1882,48 @@ impl<'a> Iterator for IndexSeekIterInner<'a> {
18381882}
18391883
18401884pub struct CommittedIndexIter < ' a > {
1885+ ctx : & ' a ExecutionContext < ' a > ,
18411886 table_id : TableId ,
18421887 tx_state : & ' a TxState ,
18431888 committed_state : & ' a CommittedState ,
18441889 committed_rows : BTreeIndexRangeIter < ' a > ,
1890+ num_committed_rows_fetched : u64 ,
1891+ }
1892+
1893+ impl Drop for CommittedIndexIter < ' _ > {
1894+ fn drop ( & mut self ) {
1895+ DB_METRICS
1896+ . rdb_num_index_seeks
1897+ . with_label_values (
1898+ & self . ctx . txn_type ( ) ,
1899+ & self . ctx . database ( ) ,
1900+ self . ctx . reducer_name ( ) . unwrap_or_default ( ) ,
1901+ & self . table_id . 0 ,
1902+ )
1903+ . inc ( ) ;
1904+
1905+ // Increment number of index keys scanned
1906+ DB_METRICS
1907+ . rdb_num_keys_scanned
1908+ . with_label_values (
1909+ & self . ctx . txn_type ( ) ,
1910+ & self . ctx . database ( ) ,
1911+ self . ctx . reducer_name ( ) . unwrap_or_default ( ) ,
1912+ & self . table_id . 0 ,
1913+ )
1914+ . inc_by ( self . committed_rows . keys_scanned ( ) ) ;
1915+
1916+ // Increment number of rows fetched
1917+ DB_METRICS
1918+ . rdb_num_rows_fetched
1919+ . with_label_values (
1920+ & self . ctx . txn_type ( ) ,
1921+ & self . ctx . database ( ) ,
1922+ self . ctx . reducer_name ( ) . unwrap_or_default ( ) ,
1923+ & self . table_id . 0 ,
1924+ )
1925+ . inc_by ( self . num_committed_rows_fetched ) ;
1926+ }
18451927}
18461928
18471929impl < ' a > Iterator for CommittedIndexIter < ' a > {
@@ -1856,6 +1938,7 @@ impl<'a> Iterator for CommittedIndexIter<'a> {
18561938 . get ( & self . table_id )
18571939 . map_or ( false , |table| table. contains ( row_id) )
18581940 } ) {
1941+ self . num_committed_rows_fetched += 1 ;
18591942 return Some ( get_committed_row ( self . committed_state , & self . table_id , row_id) ) ;
18601943 }
18611944
0 commit comments