MDEV-39942: use actual_rec_per_key in loose scan sj optimization#5284
MDEV-39942: use actual_rec_per_key in loose scan sj optimization#5284bsrikanth-mariadb wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates Loose_scan_opt in sql/opt_subselect.h to call actual_rec_per_key() instead of directly accessing the rec_per_key array. The reviewer pointed out a potential precision loss issue because the returned floating-point value is assigned to a ulong variable (rpc), which can lead to inaccurate optimizer estimations. A refactoring was suggested to use a double type and avoid assignment inside the conditional statement.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| ulong rpc; | ||
| if ((rpc= s->table->key_info[key].rec_per_key[max_loose_keypart])) | ||
| if ((rpc= s->table->key_info[key].actual_rec_per_key( | ||
| max_loose_keypart))) | ||
| records= records / rpc; |
There was a problem hiding this comment.
The variable rpc is declared as ulong, but actual_rec_per_key() returns a floating-point value (rec_per_key_t, which is typically double). Assigning it to a ulong causes truncation and precision loss, which can lead to inaccurate cost/cardinality estimations in the optimizer.
Additionally, avoiding assignment inside the if condition improves readability.
double rpc = s->table->key_info[key].actual_rec_per_key(max_loose_keypart);
if (rpc > 0)
records= records / rpc;feb21a3 to
5d44415
Compare
The filtered out value in the explain plan output should be determined based on the actual records per key value in the index. Instead, rec_per_key[] is used.
5d44415 to
6ffa772
Compare
The filtered out value in the explain plan output should be determined based on the actual records per key value in the index. Instead, rec_per_key[] is used.