Skip to content

BatchGet doesn't convert the type according to the column type. #60523

@YangKeao

Description

@YangKeao

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

func TestBatchGetType(t *testing.T) {
       ts := servertestkit.CreateTidbTestSuite(t)

       ts.RunTests(t, nil, func(dbt *testkit.DBTestKit) {
               dbt.MustExec("use test;")
               dbt.MustExec("create table t (id1 varchar(255) collate utf8mb4_general_ci, id2 varchar(255) collate utf8mb4_general_ci, primary key (id1, id2));")
               dbt.MustExec("insert into t values ('a', 'b'), ('c', 'd');")

               conn, err := dbt.GetDB().Conn(context.Background())
               require.NoError(t, err)
               defer func() {
                       require.NoError(t, conn.Close())
               }()

               conn.ExecContext(context.Background(), "set @@session.collation_connection = 'utf8mb4_general_ci'")
               stmt, err := conn.PrepareContext(context.Background(), "select * from t where (id1, id2) in ((?, ?), (?, ?))")
			   require.NoError(t, err)

			   rows, err := stmt.Query("A", "B", "C", "D");
			   require.NoError(t, err)

			   ts.CheckRows(t, rows, "a b\nc d")
       })
}

It used BatchGet. The parameter "?" has type "string collate utf8mb4_bin" (because TiDB doesn't set collation for parameter according to the connection collation. We should consider this issue later). Reference:

dVal, err := d.ConvertTo(evalCtx.TypeCtx(), &col.FieldType)

2. What did you expect to see? (Required)

The test pass

3. What did you see instead (Required)

The test failed

4. What is your TiDB version? (Required)

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-6.1This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.affects-8.5This bug affects the 8.5.x(LTS) versions.severity/majorsig/plannerSIG: Plannertype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions