diff --git a/cmd/explaintest/r/explain_easy_stats.result b/cmd/explaintest/r/explain_easy_stats.result index d4bf4c9026156..b0f5e6b277859 100644 --- a/cmd/explaintest/r/explain_easy_stats.result +++ b/cmd/explaintest/r/explain_easy_stats.result @@ -179,7 +179,9 @@ id estRows task access object operator info Point_Get 1.00 root table:index_prune, index:PRIMARY(a, b) explain format = 'brief' select * from index_prune WHERE a = 1010010404050976781 AND b = 26467085526790 GROUP BY b ORDER BY a limit 1; id estRows task access object operator info -Point_Get 1.00 root table:index_prune, index:PRIMARY(a, b) +TopN 1.00 root test.index_prune.a, offset:0, count:1 +└─StreamAgg 1.00 root group by:test.index_prune.b, funcs:firstrow(test.index_prune.a)->test.index_prune.a, funcs:firstrow(test.index_prune.b)->test.index_prune.b, funcs:firstrow(test.index_prune.c)->test.index_prune.c + └─Point_Get 1.00 root table:index_prune, index:PRIMARY(a, b) drop table if exists t1, t2, t3, index_prune; set @@session.tidb_opt_insubq_to_join_and_agg=1; drop table if exists tbl; diff --git a/executor/executor_test.go b/executor/executor_test.go index 38f64cc93b787..01227e98bc67f 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -4999,6 +4999,14 @@ func TestIsPointGet(t *testing.T) { } } +func TestPointGetOrderby(t *testing.T) { + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("create table t (i int key)") + require.Equal(t, tk.ExecToErr("select * from t where i = 1 order by j limit 10;").Error(), "[planner:1054]Unknown column 'j' in 'order clause'") +} + func TestClusteredIndexIsPointGet(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) diff --git a/planner/core/point_get_plan.go b/planner/core/point_get_plan.go index caa3051360139..96e4347227553 100644 --- a/planner/core/point_get_plan.go +++ b/planner/core/point_get_plan.go @@ -1012,7 +1012,7 @@ func tryWhereIn2BatchPointGet(ctx sessionctx.Context, selStmt *ast.SelectStmt) * // 3. All the columns must be public and not generated. // 4. The condition is an access path that the range is a unique key. func tryPointGetPlan(ctx sessionctx.Context, selStmt *ast.SelectStmt, check bool) *PointGetPlan { - if selStmt.Having != nil { + if selStmt.Having != nil || selStmt.OrderBy != nil { return nil } else if selStmt.Limit != nil { count, offset, err := extractLimitCountOffset(ctx, selStmt.Limit)