Conversation
DerZc
force-pushed
the
fix-mdev-40762
branch
from
September 21, 2026 04:52
fdee204 to
400f29b
Compare
…s DESC key part GROUP BY with MAX() can return the wrong extremum when loose index scan considers indexes with different key-part ordering. A later candidate index can corrupt the metadata retained for the selected plan. Index enumeration writes the current MIN/MAX argument key part directly into the variable that describes the best plan. If another index is inspected but not selected, the chosen index and its argument-key metadata can come from different candidates. Track the MIN/MAX argument key part in a variable local to each candidate index. Use that candidate-local pointer for gap, infix, and predicate checks. Copy the pointer into the selected plan only when that candidate becomes the best index. The regression creates ascending and descending indexes over the grouping and aggregate columns, then checks that MAX(v) for values 1, 2, and 3 returns 3. It explicitly uses InnoDB. Bug report: https://jira.mariadb.org/browse/MDEV-40762
DerZc
force-pushed
the
fix-mdev-40762
branch
from
September 21, 2026 05:56
400f29b to
39f6557
Compare
mariadb-YuchenPei
self-requested a review
September 21, 2026 06:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GROUP BY with MAX() can return the wrong extremum when loose index scan considers indexes with different key-part ordering. A later candidate index can corrupt the metadata retained for the selected plan.
Bug report: https://jira.mariadb.org/browse/MDEV-40762
Root cause
Index enumeration writes the current MIN/MAX argument key part directly into the variable that describes the best plan. If another index is inspected but not selected, the chosen index and its argument-key metadata can come from different candidates.
Changes
Regression coverage
The regression creates ascending and descending indexes over the grouping and aggregate columns, then checks that MAX(v) for values 1, 2, and 3 returns 3. It explicitly uses InnoDB.
mysql-test/main/group_min_max_index_order.resultmysql-test/main/group_min_max_index_order.testValidation
On
12.3at881b64e8add374802e1871814dd0a3a673a9b3e6:main.group_min_max_index_orderfailed on the unchanged target branch and passed with this fix.main.func_group,main.group_by,main.select.