Skip to content

MDEV-39451 Accounting for truncation to value_max_length in the ntile comparison#5282

Open
mariadb-YuchenPei wants to merge 2 commits into
10.11from
bb-10.11-mdev-39451
Open

MDEV-39451 Accounting for truncation to value_max_length in the ntile comparison#5282
mariadb-YuchenPei wants to merge 2 commits into
10.11from
bb-10.11-mdev-39451

Conversation

@mariadb-YuchenPei

Copy link
Copy Markdown
Contributor

When truncation to value_max_length in ntile function happens, the
cached string value is the truncated string. For the purpose of
comparison to determine the size of the current partition, it should
not compare the original string with the truncated string.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Copy link
Copy Markdown

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 addresses a division by zero exception in Item_sum_ntile::val_int (MDEV-39451) by using partition_row_count_ instead of get_row_count(), adding an assertion, and updating string length comparison in Cached_item_str::cmp_read_only(). It also adds corresponding test cases. Feedback was provided to improve code readability in sql/item_buff.cc by adding spaces around the assignment operator inside the if condition.

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/item_buff.cc Outdated
@mariadb-YuchenPei

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown

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 addresses a floating-point exception (division by zero) in Item_sum_ntile::val_int (MDEV-39451) by updating the logic to use partition_row_count_ instead of get_row_count(), and capping the string length in Cached_item_str::cmp_read_only(). A test case has also been added. The review feedback suggests enhancing the DBUG_ASSERT in Item_sum_ntile::val_int() to ensure current_row_count_ > 0 to prevent an underflow when evaluating (current_row_count_ - 1).

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/item_windowfunc.h
Reduce function calls that just returns partition_row_count_

Add some assertions and explanations
@mariadb-YuchenPei

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown

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 addresses a division by zero exception in Item_sum_ntile::val_int (MDEV-39451) by replacing get_row_count() with partition_row_count_ and adding safety assertions. It also updates Cached_item_str::cmp_read_only() to limit the string length. However, modifying the length of the returned String directly in cmp_read_only is dangerous as it can permanently truncate the string for other parts of the query execution; it is recommended to use a temporary String object instead.

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/item_buff.cc Outdated
… comparison

When truncation to value_max_length in ntile function happens, the
cached string value is the truncated string. For the purpose of
comparison to determine the size of the current partition, it should
not compare the original string with the truncated string.
@mariadb-YuchenPei

Copy link
Copy Markdown
Contributor Author

/gemini review

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

Copy link
Copy Markdown

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 addresses a division by zero floating-point exception in Item_sum_ntile::val_int (MDEV-39451). It updates Cached_item_str::cmp_read_only to safely copy and limit the string length using value_max_length before comparison. Additionally, it refactors Item_sum_ntile::val_int to use partition_row_count_ instead of get_row_count(), adds assertions to ensure the current row count is valid, and includes a test case to verify the fix. As there are no review comments, no further feedback is provided.

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.

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.

3 participants