[MDEV-33251] Redundant check on prebuilt::n_rows_fetched overflow Created: 2024-01-16  Updated: 2024-01-30  Resolved: 2024-01-30

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 5.5, 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11, 11.0, 11.1, 11.2, 11.3, 11.4
Fix Version/s: 10.4.34, 10.5.25, 10.6.18, 10.11.8, 11.0.6, 11.1.5, 11.2.4, 11.3.3, 11.4.2

Type: Bug Priority: Major
Reporter: Marko Mäkelä Assignee: Marko Mäkelä
Resolution: Fixed Votes: 0
Labels: performance

Issue Links:
Relates
relates to MDEV-16232 Use fewer mini-transactions Stalled

 Description   

In an InnoDB record cursor, there is a counter row_prebuilt_t::n_rows_fetched that counts records that have been fetched in a key range scan. The main purpose of this counter is to control whether to trigger a prefetch of a cache that is slated for removal in MDEV-16232.

On 64-bit systems, this counter cannot overflow. If we overestimate that InnoDB could read 10¹² or 2⁴⁰ records per second in a range scan, it would take more than half a year of such a range scan before the counter would wrap around. An even more rigid limitation would be that InnoDB only supports 2³² pages per tablespace, and you could fit at most a few thousand or 2¹² records per page, that is, there can't be more than some 2⁴⁴ records per index.

I would propose to revise an overflow check as follows, disabling it on 64-bit systems:

diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc
index 4504fabd4e0..b217f6d20fe 100644
--- a/storage/innobase/row/row0sel.cc
+++ b/storage/innobase/row/row0sel.cc
@@ -4406,13 +4406,11 @@ row_search_mvcc(
 			goto func_exit;
 		}
 
+#if SIZEOF_SIZE_T < 8
+		if (UNIV_LIKELY(~prebuilt->n_rows_fetched))
+#endif
 		prebuilt->n_rows_fetched++;
 
-		if (prebuilt->n_rows_fetched > 1000000000) {
-			/* Prevent wrap-over */
-			prebuilt->n_rows_fetched = 500000000;
-		}
-
 		mode = pcur->search_mode;
 	}
 



 Comments   
Comment by Vladislav Lesin [ 2024-01-25 ]

LGTM

Generated at Thu Feb 08 10:37:31 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.