The relationship between binding execution plans and character sets and collations

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: binding执行计划跟字符集和排序规则的关系

| username: db_user

Version: v4.0.13
The character set and collation of the two query tables are: utf8mb4, utf8mb4_general_ci
character_set_connection: utf8
collation_connection: utf8_general_ci

Create binding:
create global binding for
select …
using
select … force index(idx_created_at)

Login to the client to query:
The execution plan uses the index normally
image

Checked the dashboard, the execution plan run by the program did not use the index

Check binding information:
show global BINDINGS\G
image

set session character_set_connection=utf8mb4;
At this time, the client’s execution plan also does not use the binding index

So I thought it might be a problem with the character set and collation
set session collation_connection=utf8mb4_general_ci;
Delete the binding and then recreate the binding
Create binding:
create global binding for
select …
using
select … force index(idx_created_at)

At this time, the binding information
image

At this time, the program can use the index normally. When we set the connection-related parameters to utf8mb4 and utf8mb4_general_ci, the client can also use the index normally. But after talking with the developers, they said that the connection configuration of the program is also utf8. I can only say that I don’t understand.

| username: h5n1 | Original post link

It looks like the program connection is not actually using utf8. After version 4.0.14, the character set no longer affects SPM. util, types: don't let SPM be affected by charset (#23161) by ti-srebot · Pull Request #23295 · pingcap/tidb · GitHub

| username: db_user | Original post link

After checking, the JDBC parameter is indeed utf8, which is what I find strange :joy:. I tested version 4.0.14 and it works, but the issue with version 4.0.13 is still very strange.

| username: db_user | Original post link

This topic will be automatically closed 60 days after the last reply. No new replies are allowed.