Skip to content

Commit 8489d9d

Browse files
inikepMartin Hansson
authored andcommitted
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: As a future optimization, it would likely be beneficial to communicate the LIMIT value to the executor so that it could reduce the buffer size to that value - or not allocate a buffer at all in case of LIMIT 1.
1 parent 272666d commit 8489d9d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

sql/sql_executor.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ bool set_record_buffer(TABLE *table, double expected_rows_to_fetch) {
739739
const ha_rows local_max_rows = (MAX_RECORD_BUFFER_SIZE / record_size);
740740
rows_in_buffer = std::clamp(rows_in_buffer, min_rows, local_max_rows);
741741
}
742+
743+
// Cap the number of rows according to handler's wish.
744+
rows_in_buffer = std::min(rows_in_buffer, max_rows);
742745
}
743746

744747
// After adjustments made above, we still need a minimum of 2 rows to

0 commit comments

Comments
 (0)