Skip to content

Commit b37b166

Browse files
YangKeaoti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#60524
Signed-off-by: ti-chi-bot <[email protected]>
1 parent e5ec1ed commit b37b166

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

pkg/planner/core/point_get_plan.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -793,15 +793,13 @@ func newBatchPointGetPlan(
793793
}
794794
var values []types.Datum
795795
var valuesParams []*expression.Constant
796-
var pairs []nameValuePair
797796
switch x := item.(type) {
798797
case *ast.RowExpr:
799798
// The `len(values) == len(valuesParams)` should be satisfied in this mode
800799
if len(x.Values) != len(whereColNames) {
801800
return nil
802801
}
803802
values = make([]types.Datum, len(x.Values))
804-
pairs = make([]nameValuePair, 0, len(x.Values))
805803
valuesParams = make([]*expression.Constant, len(x.Values))
806804
initTypes := false
807805
if indexTypes == nil { // only init once
@@ -818,7 +816,10 @@ func newBatchPointGetPlan(
818816
return nil
819817
}
820818
values[permIndex] = *dval
819+
<<<<<<< HEAD
821820
pairs = append(pairs, nameValuePair{colName: whereColNames[index], value: *dval})
821+
=======
822+
>>>>>>> 1f9bdd65a5e (planner: fix the issue that the type of `BatchGet` with multiple columns is incorrect (#60524))
822823
case *driver.ParamMarkerExpr:
823824
con, err := expression.ParamMarkerExpression(ctx, innerX, true)
824825
if err != nil {
@@ -837,7 +838,10 @@ func newBatchPointGetPlan(
837838
if initTypes {
838839
indexTypes[permIndex] = &colInfos[index].FieldType
839840
}
841+
<<<<<<< HEAD
840842
pairs = append(pairs, nameValuePair{colName: whereColNames[index], value: *dval})
843+
=======
844+
>>>>>>> 1f9bdd65a5e (planner: fix the issue that the type of `BatchGet` with multiple columns is incorrect (#60524))
841845
default:
842846
return nil
843847
}
@@ -854,7 +858,6 @@ func newBatchPointGetPlan(
854858
}
855859
values = []types.Datum{*dval}
856860
valuesParams = []*expression.Constant{nil}
857-
pairs = append(pairs, nameValuePair{colName: whereColNames[0], value: *dval})
858861
case *driver.ParamMarkerExpr:
859862
if len(whereColNames) != 1 {
860863
return nil
@@ -876,7 +879,6 @@ func newBatchPointGetPlan(
876879
if indexTypes == nil { // only init once
877880
indexTypes = []*types.FieldType{&colInfos[0].FieldType}
878881
}
879-
pairs = append(pairs, nameValuePair{colName: whereColNames[0], value: *dval})
880882

881883
default:
882884
return nil

pkg/server/tests/tidb_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,3 +3218,46 @@ func TestAuthSocket(t *testing.T) {
32183218
ts.CheckRows(t, rows, "u2@%")
32193219
})
32203220
}
3221+
3222+
func TestBatchGetTypeForRowExpr(t *testing.T) {
3223+
ts := servertestkit.CreateTidbTestSuite(t)
3224+
3225+
// single columns
3226+
ts.RunTests(t, nil, func(dbt *testkit.DBTestKit) {
3227+
dbt.MustExec("use test;")
3228+
dbt.MustExec("create table t1 (id varchar(255) collate utf8mb4_general_ci, primary key (id));")
3229+
dbt.MustExec("insert into t1 values ('a'), ('c');")
3230+
3231+
conn, err := dbt.GetDB().Conn(context.Background())
3232+
require.NoError(t, err)
3233+
defer func() {
3234+
require.NoError(t, conn.Close())
3235+
}()
3236+
_, err = conn.ExecContext(context.Background(), "set @@session.collation_connection = 'utf8mb4_general_ci'")
3237+
require.NoError(t, err)
3238+
stmt, err := conn.PrepareContext(context.Background(), "select * from t1 where id in (?, ?)")
3239+
require.NoError(t, err)
3240+
rows, err := stmt.Query("A", "C")
3241+
require.NoError(t, err)
3242+
ts.CheckRows(t, rows, "a\nc")
3243+
})
3244+
3245+
// multiple columns
3246+
ts.RunTests(t, nil, func(dbt *testkit.DBTestKit) {
3247+
dbt.MustExec("use test;")
3248+
dbt.MustExec("create table t2 (id1 varchar(255) collate utf8mb4_general_ci, id2 varchar(255) collate utf8mb4_general_ci, primary key (id1, id2));")
3249+
dbt.MustExec("insert into t2 values ('a', 'b'), ('c', 'd');")
3250+
3251+
conn, err := dbt.GetDB().Conn(context.Background())
3252+
require.NoError(t, err)
3253+
defer func() {
3254+
require.NoError(t, conn.Close())
3255+
}()
3256+
conn.ExecContext(context.Background(), "set @@session.collation_connection = 'utf8mb4_general_ci'")
3257+
stmt, err := conn.PrepareContext(context.Background(), "select * from t2 where (id1, id2) in ((?, ?), (?, ?))")
3258+
require.NoError(t, err)
3259+
rows, err := stmt.Query("A", "B", "C", "D")
3260+
require.NoError(t, err)
3261+
ts.CheckRows(t, rows, "a b\nc d")
3262+
})
3263+
}

0 commit comments

Comments
 (0)