From 1265b350dcf008a0bbfe5d51bf3f3bcfdc502467 Mon Sep 17 00:00:00 2001 From: ZhuoZhi <517770911@qq.com> Date: Thu, 17 Jun 2021 20:38:38 +0800 Subject: [PATCH] cherry pick #25477 to release-5.0 Signed-off-by: ti-srebot --- executor/point_get_test.go | 14 ++++++++++++++ planner/core/point_get_plan.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/executor/point_get_test.go b/executor/point_get_test.go index 0360add8228e5..9895364c89763 100644 --- a/executor/point_get_test.go +++ b/executor/point_get_test.go @@ -158,6 +158,20 @@ func (s *testPointGetSuite) TestPointGetDataTooLong(c *C) { tk.MustExec("drop table if exists PK_1389;") } +// 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 6f3d524ca7490..5e4e0e46f864b 100644 --- a/planner/core/point_get_plan.go +++ b/planner/core/point_get_plan.go @@ -665,7 +665,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 }