Skip to content

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
MariaDB:12.3from
DerZc:fix-mdev-40820
Open

DerZc wants to merge 1 commit into
MariaDB:12.3from
DerZc:fix-mdev-40820

Conversation

@DerZc

@DerZc DerZc commented Sep 21, 2026

Copy link
Copy Markdown

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

  • 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.

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.test
  • mysql-test/main/partition_mrr_distinct.result

Validation

On 12.3 at 881b64e8add374802e1871814dd0a3a673a9b3e6:

  • The server build passed.
  • main.partition_mrr_distinct failed on the unchanged target branch and passed with this fix.
  • Existing MTR tests passed: main.func_group, main.group_by, main.select.
  • MTR reported no test-state cleanup failures.
  • The full regression suite was not run.

@CLAassistant

CLAassistant commented Sep 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants