From f9955bcb0e2ebf493db566581d58d2f81c85f76c Mon Sep 17 00:00:00 2001 From: Martin Hansson Date: Thu, 4 Dec 2025 16:05:59 +0000 Subject: [PATCH] PS-10232 [8.0]: Fix performance regression by limiting `rows_in_buffer` to query `LIMIT` A follow up fix (2969af5) for "Bug#36775910: Record buffer not set in index range scans" caused a performance regression by failing to respect the handler's recommendation to cap on number of rows in the record buffer (at the time of writing hard-coded to 100 for InnoDB). This caused a performance regression which is most pronounced when using a small LIMIT. Fixed by re-introducing the cap. Future work: It would likely be beneficial to communicate the LIMIT value to the executor so that it could reduce the buffer size accordingly - or not allocate a buffer at all in case of LIMIT 1. --- sql/sql_executor.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sql/sql_executor.cc b/sql/sql_executor.cc index a905c1f0b50a..ebfeb7861849 100644 --- a/sql/sql_executor.cc +++ b/sql/sql_executor.cc @@ -741,6 +741,9 @@ bool set_record_buffer(TABLE *table, double expected_rows_to_fetch) { } } + // Do not allocate space for more rows than the handler asked for. + rows_in_buffer = std::min(rows_in_buffer, max_rows); + // After adjustments made above, we still need a minimum of 2 rows to // use a record buffer. if (rows_in_buffer <= 1) {