Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary Hash VIndex Function With HexVals Always Uses First Shard #9275

Closed
mattlord opened this issue Nov 22, 2021 · 0 comments · Fixed by #9277
Closed

Binary Hash VIndex Function With HexVals Always Uses First Shard #9275

mattlord opened this issue Nov 22, 2021 · 0 comments · Fixed by #9277
Assignees

Comments

@mattlord
Copy link
Contributor

mattlord commented Nov 22, 2021

Overview of the Issue

In #9118 we began to normalize hex values -- Base16 Numbers (HexNum) such as 0xA1 and Binary as Hex (HexVal) such as x'A1' -- in queries so that the planner cache is used for them.

For HexVals we had use the original string literal of the form x'A1' in the BindVar and pass that original user value on to mysqld (in the golang parser we decode the string literal to the hex value of A1).

The vindex functions, however, use the BindVar values when mapping the column value to a keyspace ID and so should use the binary value actually stored in the mysql column after handling the string literal: A1. Currently we are not doing that and thus the binary hash is done on x'A1' when it should be done on A1.

Reproduction Steps

Using the docker_local container from main:

make docker_local && ./docker/local/run.sh

./201_customer_tablets.sh ; ./202_move_tables.sh ; sleep 10; ./203_switch_reads.sh ; ./204_switch_writes.sh ; ./205_clean_commerce.sh ; ./301_customer_sharded.sh ; ./302_new_shards.sh ; ./303_reshard.sh ; sleep 10; ./304_switch_reads.sh ; ./305_switch_writes.sh ; ./306_down_shard_0.sh

vtctlclient GetVSchema customer > /tmp/customer.json

vtctlclient ApplyVSchema -vschema "$(jq '. | .vindexes += {"binary":{"type":"binary"}}' < /tmp/customer.json)" customer

mysql customer -e "select shard from customer.binary where id = x'7901'"
mysql customer -e "select shard from customer.binary where id = x'997901'"

Test results

13.0-SNAPSHOT:

$ mysql customer -e "select shard from customer.binary where id = x'7901'"
+-------+
| shard |
+-------+
| -80   |
+-------+
$ mysql customer -e "select shard from customer.binary where id = x'997901'"
+-------+
| shard |
+-------+
| -80   |
+-------+

11.0.2:

$ mysql customer -e "select shard from customer.binary where id = x'7901'"
+-------+
| shard |
+-------+
| -80   |
+-------+
$ mysql customer -e "select shard from customer.binary where id = x'997901'"
+-------+
| shard |
+-------+
| 80-   |
+-------+

Binary version

Example:

$ vtgate --version
Version: 13.0.0-SNAPSHOT (Git revision 94c55f0832 branch 'main') built on Mon Nov 22 23:17:03 UTC 2021 by vitess@73f80c185996 using go1.17 linux/amd64
@mattlord mattlord self-assigned this Nov 22, 2021
@mattlord mattlord changed the title Binary Hash VIndex Function Always Uses First Shard Binary Hash VIndex Function With HexVals Always Uses First Shard Nov 23, 2021
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 a pull request may close this issue.

1 participant