Bug #107972 Contribution by Tencent: comment mistake in get_best_ror_intersect
Submitted: 26 Jul 2022 7:30 Modified: 26 Jul 2022 8:39
Reporter: Xiaodong Huang (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0.29 OS:Any
Assigned to: CPU Architecture:Any
Tags: Comment error, Contribution

[26 Jul 2022 7:30] Xiaodong Huang
Description:
the comment of get_best_ror_intersect:
"
find_min_ror_intersection_scan()
{
  R= select all ROR scans;
  order R by (E(#records_matched) * key_record_length).

  S= first(R); -- set of scans that will be used for ROR-
  R= R-first(S);
  min_cost= cost(S);
  min_scan= make_scan(S);
  while (R is not empty)
  {
    firstR= R - first(R);
    if (!selectivity(S + firstR < selectivity(S)))
      continue;

    S= S + first(R);
    if (cost(S) < min_cost)
    {
      min_cost= cost(S);
      min_scan= make_scan(S);
    }
  }
  return min_scan;
}
"

According to the logic of the get_best_ror_intersect, the “selectivity(S + firstR < selectivity(S))” should be fixed as “if (!selectivity(S + firstR) < selectivity(S))”.

the following code correspond the while loop in comment above.

"
while (cur_ror_scan != tree->ror_scans_end && !intersect->is_covering) {

  /* some codes */

  /* S= S + first(R);  R= R - first(R); */
  if (!ror_intersect_add(intersect, needed_fields, *cur_ror_scan, false,
                       &trace_idx,
                       force_index_merge && !use_cheapest_index_merge)) {

​     /* some codes */

​    continue;

  }

  /* some codes */

}
"

How to repeat:
Analyze the logic of get_best_ror_intersect.

Suggested fix:
the comment “selectivity(S + firstR < selectivity(S))” should be fixed as “if (!selectivity(S + firstR) < selectivity(S))”.
[26 Jul 2022 8:39] MySQL Verification Team
Hello Xiaodong,

Thank you for the report and contribution.

regards,
Umesh