Browse Source

Bug#34422267 - Contribution by Tencent: comment mistake in get_best_ror_intersect

Description:
The function get_best_ror_intersect is responsible for selecting
the optimal combination of ROR scans that minimize cost while
improving selectivity. It iteratively adds scans to a selected
set (S), ensuring that each addition results in improved selectivity.
If selectivity improves, the function then evaluates whether
the cost is minimized.

The comment contained some inaccuracies:
- Incorrect Selectivity Condition:
A missing parentheses caused the condition to be misinterpreted,
leading to incorrect logic. The function intends to check whether
adding a scan improves selectivity before including it in the set.

- Loop Condition Issue:
The condition for continuing the loop did not properly reduce R in
the comment which meant it was an infinite loop.

Fix:
The comment of the function is fixed addressing the issues.

The set should include the scan before comparing the
selectivity with the initial set and thus the selectivity condition
in the comment is fixed by properly enclosing the expression in
parentheses to reflect the intended logic.

Ensured that R is properly reduced in each iteration to maintain
correctness.

Change-Id: Ie197af8211a5ef05a5118a33b8b543d354475780
bb-10.6-release
Ayush Gupta 5 months ago
committed by Sergei Golubchik
parent
commit
29775c03c1
  1. 11
      sql/opt_range.cc

11
sql/opt_range.cc

@ -7132,21 +7132,24 @@ static bool ror_intersect_add(ROR_INTERSECT_INFO *info,
order R by (E(#records_matched) * key_record_length).
S= first(R); -- set of scans that will be used for ROR-intersection
R= R-first(S);
R= R - 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)))
firstR= first(R);
if (!selectivity(S + firstR) < selectivity(S))
{
R= R - firstR;
continue;
}
S= S + first(R);
if (cost(S) < min_cost)
{
min_cost= cost(S);
min_scan= make_scan(S);
}
R= R - firstR; -- Remove the processed scan from R
}
return min_scan;
}

Loading…
Cancel
Save