Skip to content

MDEV-40479 SELECT, order by desc, on partitioned table leads to incorrect results - #5708

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

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

Conversation

@DerZc

@DerZc DerZc commented Sep 21, 2026

Copy link
Copy Markdown

A descending scan of a partitioned table through a secondary index can stop early and omit qualifying rows.

Bug report: https://jira.mariadb.org/browse/MDEV-40479

Root cause

ha_partition::handle_unordered_prev() validates the unordered prefix with key number 0 instead of the active index. If the secondary index has a different layout from the primary key, that comparison can incorrectly signal end of file.

Changes

  • Pass active_index to key_cmp_if_same() so the prefix comparison uses the index that produced the current row.

Regression coverage

The regression scans a RANGE-partitioned table using a secondary (b,c) index and checks that ORDER BY c DESC returns all three values: 15, 11, and 6.

  • mysql-test/main/partition_reverse_prefix_scan.test
  • mysql-test/main/partition_reverse_prefix_scan.result

Validation

On 12.3 at 881b64e8add374802e1871814dd0a3a673a9b3e6:

  • The server build passed.
  • main.partition_reverse_prefix_scan failed on the unchanged target branch and passed with this fix.
  • Existing MTR tests passed: 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.

…rect results

A descending scan of a partitioned table through a secondary index can
stop early and omit qualifying rows.

ha_partition::handle_unordered_prev() validates the unordered prefix
with key number 0 instead of the active index. If the secondary index
has a different layout from the primary key, that comparison can
incorrectly signal end of file.

Pass active_index to key_cmp_if_same() so the prefix comparison uses the
index that produced the current row.

The regression scans a RANGE-partitioned table using a secondary (b,c)
index and checks that ORDER BY c DESC returns all three values: 15, 11,
and 6.

Bug report: https://jira.mariadb.org/browse/MDEV-40479
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