diff --git a/executor/point_get_test.go b/executor/point_get_test.go index 405b5892d26e1..881ea0f53a4d8 100644 --- a/executor/point_get_test.go +++ b/executor/point_get_test.go @@ -208,6 +208,20 @@ func (s *testPointGetSuite) TestIssue25489(c *C) { tk.MustExec("drop table if exists UK_RP16939;") } +// issue #25320 +func (s *testPointGetSuite) TestDistinctPlan(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists test_distinct;") + tk.MustExec(`CREATE TABLE test_distinct ( + id bigint(18) NOT NULL COMMENT '主键', + b bigint(18) NOT NULL COMMENT '用户ID', + PRIMARY KEY (id) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;`) + tk.MustExec("insert into test_distinct values (123456789101112131,223456789101112131),(123456789101112132,223456789101112131);") + tk.MustQuery("select distinct b from test_distinct where id in (123456789101112131,123456789101112132);").Check(testkit.Rows("223456789101112131")) +} + func (s *testPointGetSuite) TestPointGetCharPK(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec(`use test;`) diff --git a/planner/core/point_get_plan.go b/planner/core/point_get_plan.go index 1214b1b776cd2..6562894eae2db 100644 --- a/planner/core/point_get_plan.go +++ b/planner/core/point_get_plan.go @@ -713,7 +713,7 @@ func newBatchPointGetPlan( func tryWhereIn2BatchPointGet(ctx sessionctx.Context, selStmt *ast.SelectStmt) *BatchPointGetPlan { if selStmt.OrderBy != nil || selStmt.GroupBy != nil || - selStmt.Limit != nil || selStmt.Having != nil || + selStmt.Limit != nil || selStmt.Having != nil || selStmt.Distinct || len(selStmt.WindowSpecs) > 0 { return nil }