Skip to content

PS-10481: Fix range optimizer full table scan for IN() with oversized…#5875

Open
percona-mhansson wants to merge 1 commit intopercona:trunkfrom
percona-mhansson:ps-10481-trunk
Open

PS-10481: Fix range optimizer full table scan for IN() with oversized…#5875
percona-mhansson wants to merge 1 commit intopercona:trunkfrom
percona-mhansson:ps-10481-trunk

Conversation

@percona-mhansson
Copy link
Copy Markdown
Contributor

… values

The range optimizer did not handle the case of search keys being longer than the index's key length. In this case, a search key could be created, and in the case of WHERE clauses with multiple sufficient conditions - either OR or IN conditions - it had to fall back to table scan.

For binary collations, this is fine: an equality condition involving a value that wouldn't have fit the column can never match, and so we can safely just ignore it in a disjuntion expression. For other collations, however, a longer sequence in code points can match a shorter one, and there is no upper limit.

Fixed by allocating a larger buffer in case the common key creationg fails due to truncation. We allocate as much space as the worst-case scenario and then some, heeding the advice in comment above strnxfrmlen(). For full indexes we just render the entire string, and for prefixes a string we the same amount of characters (really code points) as the index's declared key length.

Putting the test case in type_varchar since this is ultimately a trait of the VARCHAR type.

… values

The range optimizer did not handle the case of search keys being longer than the
index's key length. In this case, a search key could be created, and in the case
of WHERE clauses with multiple sufficient conditions - either OR or IN
conditions - it had to fall back to table scan.

For binary collations, this is fine: an equality condition involving a value
that wouldn't have fit the column can never match, and so we can safely just
ignore it in a disjuntion expression. For other collations, however, a longer
sequence in code points can match a shorter one, and there is no upper limit.

Fixed by allocating a larger buffer in case the common key creationg fails due
to truncation. We allocate as much space as the worst-case scenario and then
some, heeding the advice in comment above `strnxfrmlen()`. For full indexes we
just render the entire string, and for prefixes a string we the same amount of
characters (really code points) as the index's declared key length.

Putting the test case in type_varchar since this is ultimately a trait of the
VARCHAR type.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant