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

Bug Report: User defined variables lose binary encoding information #16989

Closed
dbussink opened this issue Oct 17, 2024 · 0 comments · Fixed by #16988
Closed

Bug Report: User defined variables lose binary encoding information #16989

dbussink opened this issue Oct 17, 2024 · 0 comments · Fixed by #16988

Comments

@dbussink
Copy link
Contributor

Overview of the Issue

When using user defined variables in a session, information is lost when the value is passed down the MySQL when interpolated.

In the reproduction below, it can be seen that the collation for the @pt variable is returned as utf8mb4_0900_ai_ci. What is happening here is that the bind variables are sent down to vttablet and there interpolated, but then the literal string is used without any annotation.

So MySQL ends up running select collation('foo', rand();, which means the collation information is lost. We need to make sure that the variable is escaped as a proper binary string.

Reproduction Steps

mysql> set @p2 = 'foo';
Query OK, 0 rows affected (0.01 sec)

mysql> select @p2;
Field   1:  `@p2`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  utf8mb4_0900_ai_ci (255)
Length:     0
Max_length: 3
Decimals:   0
Flags:      


+------+
| @p2  |
+------+
| foo  |
+------+
1 row in set (0.00 sec)

mysql> select collation(@p2), rand();
Field   1:  `collation(@p2)`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       VAR_STRING
Collation:  utf8mb4_0900_ai_ci (255)
Length:     256
Max_length: 18
Decimals:   31
Flags:      

Field   2:  `rand()`
Catalog:    `def`
Database:   ``
Table:      ``
Org_table:  ``
Type:       DOUBLE
Collation:  binary (63)
Length:     23
Max_length: 17
Decimals:   31
Flags:      NOT_NULL BINARY NUM 


+--------------------+-------------------+
| collation(@p2)     | rand()            |
+--------------------+-------------------+
| utf8mb4_0900_ai_ci | 0.048512788534642 |
+--------------------+-------------------+
1 row in set (0.00 sec)

Binary Version

-

Operating System and Environment details

-

Log Fragments

-
@dbussink dbussink self-assigned this Oct 17, 2024
mattrobenolt added a commit to planetscale/cli that referenced this issue Nov 6, 2024
mattrobenolt added a commit to planetscale/psdbproxy that referenced this issue Nov 6, 2024
mattrobenolt added a commit to planetscale/psdbproxy that referenced this issue Nov 6, 2024
mattrobenolt added a commit to planetscale/cli that referenced this issue Nov 6, 2024
mattrobenolt added a commit to planetscale/cli that referenced this issue Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant