Skip to content

MDEV-39942: use actual_rec_per_key in loose scan sj optimization#5284

Draft
bsrikanth-mariadb wants to merge 1 commit into
mainfrom
13.1-MDEV-39942-loose-scan-sj-opt-uses-rec_per_key
Draft

MDEV-39942: use actual_rec_per_key in loose scan sj optimization#5284
bsrikanth-mariadb wants to merge 1 commit into
mainfrom
13.1-MDEV-39942-loose-scan-sj-opt-uses-rec_per_key

Conversation

@bsrikanth-mariadb

@bsrikanth-mariadb bsrikanth-mariadb commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

While performing loose scan semi-join optimization in
Loose_scan_opt::check_ref_access_part1() [opt_subselect.h],
the filtered value in the explain plan was in-consistent for a table
with index when same data was inserted using "insert into t1 values()...",
and "insert into t1 select * from t2". This is noticed when
rec_per_key[] was used to get the number of records during optimization.

However, when actual_rec_per_key() is used to get the number of records,
we don't notice this discrepancy.

This PR changes the rec_per_key[] usage to actual_rec_per_key() in the
method Loose_scan_opt::check_ref_access_part1() [opt_subselect.h]

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread sql/opt_subselect.h
@bsrikanth-mariadb bsrikanth-mariadb marked this pull request as draft June 26, 2026 11:23
@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 13.1-MDEV-39942-loose-scan-sj-opt-uses-rec_per_key branch 2 times, most recently from 5d44415 to 6ffa772 Compare June 26, 2026 12:48
While performing loose scan semi-join optimization in
Loose_scan_opt::check_ref_access_part1() [opt_subselect.h],
the filtered value in the explain plan was in-consistent for a table
with index when same data was inserted using "insert into t1 values()...",
and "insert into t1 select * from t2". This is noticed when
rec_per_key[] was used to get the number of records during optimization.

However, when actual_rec_per_key() is used to get the number of records,
we don't notice this discrepancy.

This PR changes the rec_per_key[] usage to actual_rec_per_key() in the
method Loose_scan_opt::check_ref_access_part1() [opt_subselect.h]
@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 13.1-MDEV-39942-loose-scan-sj-opt-uses-rec_per_key branch from 6ffa772 to f17beec Compare June 29, 2026 03:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant