MDEV-40820 Wrong results: SELECT DISTINCT / GROUP BY returns duplicate rows on a RANGE-partitioned table when served by a covering index range scan - #5712
Open
DerZc wants to merge 1 commit into
Conversation
…e rows on a RANGE-partitioned table when served by a covering index range scan SELECT DISTINCT or GROUP BY can return duplicate values from a RANGE- partitioned table when a covering index range scan incorrectly bypasses the merge of partition scans. ha_partition::can_skip_merging_scans() checks only the current multi- range prefix. Later ranges can have different prefix values, so the partition outputs do not have the ordering required to skip the priority-queue merge. Check every multi-range entry before bypassing the partition-scan merge. Require both endpoints to bind the complete unordered prefix and to agree on its bytes. Require that prefix to be the same across all ranges; otherwise keep the normal merge. The regression uses two date prefixes across several partitions and checks that SELECT DISTINCT returns each date exactly once. Bug report: https://jira.mariadb.org/browse/MDEV-40820
DerZc
force-pushed
the
fix-mdev-40820
branch
from
September 21, 2026 05:56
443cc7b to
f43c72b
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.
SELECT DISTINCT or GROUP BY can return duplicate values from a RANGE-partitioned table when a covering index range scan incorrectly bypasses the merge of partition scans.
Bug report: https://jira.mariadb.org/browse/MDEV-40820
Root cause
ha_partition::can_skip_merging_scans() checks only the current multi-range prefix. Later ranges can have different prefix values, so the partition outputs do not have the ordering required to skip the priority-queue merge.
Changes
Regression coverage
The regression uses two date prefixes across several partitions and checks that SELECT DISTINCT returns each date exactly once.
mysql-test/main/partition_mrr_distinct.testmysql-test/main/partition_mrr_distinct.resultValidation
On
12.3at881b64e8add374802e1871814dd0a3a673a9b3e6:main.partition_mrr_distinctfailed on the unchanged target branch and passed with this fix.main.func_group,main.group_by,main.select.