Skip to content

MDEV-37000 disable optimization for Aria remove_key() on affected MSVC#5414

Open
vaintroub wants to merge 1 commit into
10.6from
MDEV-37000
Open

MDEV-37000 disable optimization for Aria remove_key() on affected MSVC#5414
vaintroub wants to merge 1 commit into
10.6from
MDEV-37000

Conversation

@vaintroub

Copy link
Copy Markdown
Member

The Aria remove_key() helper can miscompile in x64 MSVC builds when optimization is enabled, leading to 'Index is corrupt' during DELETE.

Apply the same #pragma optimize("g", off) workaround already used in MyISAM, and limit it to _MSC_VER >= 1930 && _MSC_VER < 1951.

The upper bound for affected MSVC is just the newest MSVC version in VS2026, where the bug is no longer reproducible. Also, MSVC release notes https://learn.microsoft.com/en-us/visualstudio/releases/2026/release-notes list multiple fixes for 19.50 x64 optimizer and codegen bugs.

The Aria remove_key() helper can miscompile in x64 MSVC builds when
optimization is enabled, leading to 'Index is corrupt' during DELETE.

Apply the same #pragma optimize("g", off) workaround already used in
MyISAM, and limit it to _MSC_VER >= 1930 && _MSC_VER < 1951.

The upper bound for affected MSVC is just the newest MSVC version in
VS2026, where the bug is no longer reproducible. Also, MSVC release notes
https://learn.microsoft.com/en-us/visualstudio/releases/2026/release-notes
list multiple fixes for 19.50 x64 optimizer and codegen bugs.

@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 addresses MDEV-37000 by disabling compiler optimization for the remove_key function in both Aria (storage/maria/ma_delete.c) and MyISAM (storage/myisam/mi_delete.c) storage engines when compiled with affected MSVC versions, and adds a corresponding test case. The reviewer suggests adjusting the MSVC version check from _MSC_VER < 1951 to _MSC_VER < 1950 to avoid unnecessarily disabling optimizations on MSVC version 19.50, where the compiler bug is already fixed.

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 storage/maria/ma_delete.c
Comment on lines +1338 to +1340
#if defined(_MSC_VER) && defined(_M_X64) && _MSC_VER >= 1930 && _MSC_VER < 1951
#pragma optimize("g", off)
#endif

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.

medium

Since the compiler bug is fixed in MSVC version 19.50 (VS2026), that version is not affected. Using _MSC_VER < 1951 unnecessarily disables optimization for version 19.50. Changing the upper bound to _MSC_VER < 1950 ensures that optimization is only disabled on the affected versions (19.30 to 19.49).

#if defined(_MSC_VER) && defined(_M_X64) && _MSC_VER >= 1930 && _MSC_VER < 1950
#pragma optimize("g", off)
#endif

Comment thread storage/maria/ma_delete.c
Comment on lines +1481 to +1483
#if defined(_MSC_VER) && defined(_M_X64) && _MSC_VER >= 1930 && _MSC_VER < 1951
#pragma optimize("", on)
#endif

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.

medium

Update the upper bound check here as well to match the change in the corresponding #pragma optimize("g", off) block.

#if defined(_MSC_VER) && defined(_M_X64) && _MSC_VER >= 1930 && _MSC_VER < 1950
#pragma optimize("", on)
#endif

Comment on lines +770 to 772
#if defined(_MSC_VER) && defined(_M_X64) && _MSC_VER >= 1930 && _MSC_VER < 1951
#pragma optimize("g", off)
#endif

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.

medium

Since the compiler bug is fixed in MSVC version 19.50 (VS2026), that version is not affected. Using _MSC_VER < 1951 unnecessarily disables optimization for version 19.50. Changing the upper bound to _MSC_VER < 1950 ensures that optimization is only disabled on the affected versions (19.30 to 19.49).

#if defined(_MSC_VER) && defined(_M_X64) && _MSC_VER >= 1930 && _MSC_VER < 1950
#pragma optimize("g", off)
#endif

Comment on lines +899 to 901
#if defined(_MSC_VER) && defined(_M_X64) && _MSC_VER >= 1930 && _MSC_VER < 1951
#pragma optimize("",on)
#endif

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.

medium

Update the upper bound check here as well to match the change in the corresponding #pragma optimize("g", off) block.

#if defined(_MSC_VER) && defined(_M_X64) && _MSC_VER >= 1930 && _MSC_VER < 1950
#pragma optimize("",on)
#endif

@vaintroub
vaintroub requested a review from sanja-byelkin July 20, 2026 15:07
@vuvova

vuvova commented Jul 20, 2026

Copy link
Copy Markdown
Member

"miscompile" how? could you be more specific?

@vaintroub

vaintroub commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

"miscompile" how? could you be more specific?

Ok, there is is some explanation in the linked ticket, https://jira.mariadb.org/browse/MDEV-27030, not by myself, but by Alexander Miloslavski. With reported bug link . That bug is recently closed as "fixed", and this matches my experience, that on the current VS2026, that test case passes without any deoptimizing pragmas, but on VS2022, it does not.

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