Skip to content

MDEV-41366 Check prefix key match in iterated partition index scan - #5821

Open
mariadb-YuchenPei wants to merge 1 commit into
12.3from
bb-12.3-mdev-41366
Open

mariadb-YuchenPei wants to merge 1 commit into
12.3from
bb-12.3-mdev-41366

Conversation

@mariadb-YuchenPei

Copy link
Copy Markdown
Contributor

The idea of Case 2 in can_skip_merging_scans is that when partition column key prefix is fixed, and the infix that is also the "partition by range" column, we can scan each partition in order. This relies on accurately returning EOF when a partition has no (more) matching rows. It is possible to have no more matching rows at the first index read of a partition in a non-exact access, in which case we need to check the prefix match to rule out false positives and return EOF correctly.

This change by itself would result in incomplete results, if Case 2 incorrectly determines the scan can iterate over partitions in order in AFTER_KEY and BEFORE_KEY reads. These reads when applied to a partition column key prefix, necessarily means seeking a different prefix value. This could result in false negatives. To that end, we strengthen the checks in Case 2 so that AFTER_KEY and BEFORE_KEY reads require both the prefix and the partitioned column itself in the keypart_map to ensure correctness.

For example, this check disqualifies the index_read_map call in an existing loose index scan testcase, causing the index scan to use both unordered (in read_range_first) and ordered.

Since we have to enumerate all flags, we include a fix of missing reverse_order for KEY_OR_PREV. The only known usecase is HANDLER ... READ which is not working correctly and due to be fixed in MDEV-41364. For consistency with other equally incorrect HANDLER cases involving other flags, we do not single out KEY_OR_PREV for special treatment (e.g. return false in can_skip_merging_scans).

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@mariadb-YuchenPei
mariadb-YuchenPei force-pushed the bb-12.3-mdev-41366 branch 2 times, most recently from 571304b to 81dcb00 Compare October 21, 2026 06:12
…with prefix

The idea of Case 2 in can_skip_merging_scans is that when partition
column key prefix is fixed, and the infix that is also the "partition
by range" column, we can scan each partition in order. To that end, we
restrict access flags to exact accesses.

Also reset m_unordered_prefix_len in the single-partition "unordered"
scan case as it skips can_skip_merging_scans, which would otherwise
leave a stale length for handle_unordered_prev.

Also include HA_READ_KEY_OR_PREV in reverse_order flags, so that it
can be considered and rejected for Case 2.
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