Failed to Delete Partition Using MyBatis in TiDB Version 4.X

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

Original topic: 使用mybatis删除分区时失败 TiDB版本为4.X

| username: TiDBer_KKqkk71j

When using MyBatis to delete a partition from a table, a java.sql.SQLException: json: cannot unmarshal string into Go value of type []string exception occurs. How should the SQL be modified in this situation?

| username: xfworld | Original post link

Can it be executed directly using the mysql client command line?

Also, what version of JDBC is being used?

| username: TiDBer_KKqkk71j | Original post link

Executing the same SQL using the MySQL client works fine, and the JDBC version is 5.2.8.

| username: xfworld | Original post link

Try switching to the TiDB-specific one

| username: WalterWj | Original post link

It seems like this is a code issue and hasn’t even reached the database execution… :rofl:

| username: TiDBer_KKqkk71j | Original post link

Thank you, master. I’ll give it a try first.

| username: TiDBer_KKqkk71j | Original post link

Tried executing directly with JDBC, but still got the exception: json: cannot unmarshal string into Go value of type string.

| username: xfworld | Original post link

Do I need to convert it to String?

alter table table drop partition [‘P20230203’]

Give it a try…

| username: TiDBer_KKqkk71j | Original post link

This won’t work. I tried it before, and it should be an exception returned by TiDB during SQL parsing.

| username: Billmay表妹 | Original post link

This doesn’t quite meet expectations. However, since the old version 4.0.x is basically no longer updated, if conditions permit, please upgrade to 6.5.0 to see if the issue still exists!

If there is a bug, it is most likely a JDBC compatibility issue. This is a fundamental feature, and we will fix it.

| username: TiDBer_KKqkk71j | Original post link

By comparing the packet capture situations of different versions of TiDB, it was found that the operation is normal under 4.0.8, while such a problem occurs in 4.0.2. By checking the release history, there are changes in the code related to partition. If TiDB before 4.0.5 is used with TiKV after 4.0.5, it will lead to unmarshal issues. Therefore, keeping both versions consistent generally avoids problems.

| username: aytrack | Original post link

May I ask which version this JDBC 5.2.8 is? It seems that MySQL Connector/J does not have a 5.2 version.

| username: TiDBer_KKqkk71j | Original post link

Sorry, I made a mistake earlier and wrote down the version of Spring. 5.2.8 is the version of Spring, and the version of mysql-connector-java is 8.0.21.

| username: aytrack | Original post link

I did not reproduce the issue using the following environment. Do you have any other parameters set when connecting to TiDB?

  • TiDB v4.0.2
  • mysql-connector-java 8.0.21
  • mybatis 3.5.6
| username: TiDBer_KKqkk71j | Original post link

MyBatis is 3.5.10, it shouldn’t be an issue with other parameters. I tried again, and version 4.0.2 throws the following exception:
java.sql.SQLException: json: cannot unmarshal string into Go value of type string
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:370)

Everything works fine with version 4.0.8.

| username: TiDBer_KKqkk71j | Original post link

I checked the MR record ddl: change drop partition and truncate partition's job args to support multi partition id array (#18419) by ti-srebot · Pull Request #18930 · pingcap/tidb · GitHub, and indeed the partition name has been modified, but I don’t know if this is the reason.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.