diff -u sql/opt_range.cc /home/psergey/dev-git2/12.0-review-MDEV-32732-loose-scan/sql/opt_range.cc
--- sql/opt_range.cc	2025-03-03 12:44:58.323222680 +0200
+++ /home/psergey/dev-git2/12.0-review-MDEV-32732-loose-scan/sql/opt_range.cc	2025-03-03 14:18:05.379944645 +0200
@@ -16209,7 +16209,7 @@
   */
   DBUG_ASSERT(!min_max_arg_part || have_min || have_max);
   bool reverse= min_max_arg_part != NULL &&
-    min_max_arg_part->key_part_flag & HA_REVERSE_SORT;
+    (min_max_arg_part->key_part_flag & HA_REVERSE_SORT);
   bool have_first= reverse ? have_max : have_min;
   bool have_last= reverse ? have_min : have_max;
 #ifdef HPUX11
@@ -16281,7 +16281,9 @@
   DBUG_RETURN(result);
 }
 
+
 /* Skip NULLs when looking for MIN. */
+
 int QUICK_GROUP_MIN_MAX_SELECT::skip_nulls(bool reverse)
 {
   int result= 0;
@@ -16296,12 +16298,12 @@
   }
 
   /*
-  If the min/max argument field is NULL, skip subsequent rows in the same
-  group with NULL in it. Notice that:
-  - if the first (or last with DESC index) row in a group doesn't have
-    a NULL in the field, no row in the same group has (because NULL <
-    any other value),
-  - min_max_arg_part->field->ptr points to some place in 'record'.
+    If the min/max argument field is NULL, skip subsequent rows in the same
+    group with NULL in it. Notice that:
+    - if the first (or last with DESC index) row in a group doesn't have
+      a NULL in the field, no row in the same group has (because NULL <
+      any other value),
+    - min_max_arg_part->field->ptr points to some place in 'record'.
   */
   DBUG_ASSERT(min_max_arg_part);
   if (min_max_arg_part->field->is_null())
@@ -16314,14 +16316,14 @@
                                     reverse ? HA_READ_BEFORE_KEY :
                                     HA_READ_AFTER_KEY);
     /*
-    Check if the new record belongs to the current group by comparing its
-    prefix with the group's prefix. If it is from the next group, then the
-    whole group has NULLs in the MIN/MAX field, so use the first record in
-    the group as a result.
-    TODO:
-    It is possible to reuse this new record as the result candidate for the
-    next call to next_min_max(true, false), and to save one lookup in the
-    next call. For this add a new member 'this->next_group_prefix'.
+      Check if the new record belongs to the current group by comparing its
+      prefix with the group's prefix. If it is from the next group, then the
+      whole group has NULLs in the MIN/MAX field, so use the first record in
+      the group as a result.
+      TODO:
+      It is possible to reuse this new record as the result candidate for the
+      next call to next_min_max(true, false), and to save one lookup in the
+      next call. For this add a new member 'this->next_group_prefix'.
     */
     if (!result)
     {
@@ -16335,12 +16337,13 @@
   return result;
 }
 
+
 /*
   Retrieve the min or max key in the next group.
 
   SYNOPSIS
     QUICK_GROUP_MIN_MAX_SELECT::next_min_max()
-    min                    [in] Whether retrieving min (true) or max (false))
+    min                    [in] Whether retrieving min (true) or max (false)
     reverse                [in] Whether the key is a descending one
 
   DESCRIPTION
@@ -16360,11 +16363,12 @@
     HA_ERR_END_OF_FILE   - "" -
     other                if some error occurred
 */
+
 int QUICK_GROUP_MIN_MAX_SELECT::next_min_max(bool min, bool reverse)
 {
   int result= 0;
-  bool last= min == reverse;
-  DBUG_ENTER("QUICK_GROUP_MIN_MAX_SELECT::next_min");
+  bool last= (min == reverse);
+  DBUG_ENTER("QUICK_GROUP_MIN_MAX_SELECT::next_min_max");
 
   /* Find the min/max key using the eventually extended group prefix. */
   if (min_max_ranges.elements > 0)
@@ -16380,9 +16384,11 @@
     if (reverse && min_max_arg_part->field->is_null())
       DBUG_RETURN(0);
     if (last)
+    {
       result= file->ha_index_read_map(record, group_prefix,
                                       make_prev_keypart_map(real_key_parts),
                                       HA_READ_PREFIX_LAST);
+    }
     /* Skip nulls if looking for MIN. */
     if (min)
       result= skip_nulls(reverse);
@@ -16537,6 +16543,7 @@
   return cmp_res;
 }
 
+
 /*
   Find the min/max key in a group that satisfies some range conditions
   for the min/max argument field.
@@ -16560,6 +16567,7 @@
     HA_ERR_END_OF_FILE   - "" -
     other                if some error
 */
+
 int QUICK_GROUP_MIN_MAX_SELECT::next_min_max_in_range(bool min, bool reverse)
 {
   ha_rkey_function find_flag;
@@ -16568,7 +16576,7 @@
   /* MDEV-36118 */
   int result= 1;
   /* Whether looking for a last key (true) or a first key (false). */
-  bool last= min == reverse;
+  bool last= (min == reverse);
 
   DBUG_ASSERT(min_max_ranges.elements > 0);
 
@@ -16635,7 +16643,7 @@
                                     find_flag);
 
     /*
-      In no key was found within this boundary: if the current range
+      If no key was found within this boundary: if the current range
       is an equality, check the next range, otherwise there
       certainly are no keys in subsequent ranges.
     */
@@ -16687,6 +16695,7 @@
   return HA_ERR_KEY_NOT_FOUND;
 }
 
+
 /*
   Update all MIN function results with the newly found value.
 
