Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#57550
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
  • Loading branch information
xhebox authored and ti-chi-bot committed Dec 10, 2024
1 parent b298e21 commit 63735c4
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,15 @@ func buildOrderedList(ctx sessionctx.Context, plan Plan, list []*ast.Assignment,
if err != nil {
return nil, true
}
<<<<<<< HEAD
expr = expression.BuildCastFunction(ctx, expr, col.GetType())
=======
castToTP := col.GetStaticType()
if castToTP.GetType() == mysql.TypeEnum && assign.Expr.GetType().EvalType() == types.ETInt {
castToTP.AddFlag(mysql.EnumSetAsIntFlag)
}
expr = expression.BuildCastFunction(ctx.GetExprCtx(), expr, castToTP)
>>>>>>> 1c059a1216d (planner: set enumsetasint if original value is int in point get (#57550))
if allAssignmentsAreConstant {
_, isConst := expr.(*expression.Constant)
allAssignmentsAreConstant = isConst
Expand Down
63 changes: 63 additions & 0 deletions pkg/planner/core/point_get_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,66 @@ func TestIssue18042(t *testing.T) {
require.Equal(t, uint64(100), tk.Session().GetSessionVars().StmtCtx.MaxExecutionTime)
tk.MustExec("drop table t")
}
<<<<<<< HEAD
=======

func TestIssue52592(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`set @@tidb_opt_fix_control = "52592:OFF"`) // affect hit counter in this ut
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a bigint unsigned primary key, b int, c int, key idx_bc(b,c))")
tk.MustExec("insert into t values(1, 1, 1), (2, 2, 2), (3, 3, 3)")
tk.MustQuery("explain format = 'brief' select * from t where a = 1").Check(testkit.Rows(
"Point_Get 1.00 root table:t handle:1",
))
tk.MustQuery("explain format = 'brief' select * from t where 1 = a").Check(testkit.Rows(
"Point_Get 1.00 root table:t handle:1",
))
tk.MustQuery("explain format = 'brief' update t set b=b+1, c=c+1 where a = 1").Check(testkit.Rows(
"Update N/A root N/A",
"└─Point_Get 1.00 root table:t handle:1",
))
tk.MustQuery("explain format = 'brief' delete from t where a = 1").Check(testkit.Rows(
"Delete N/A root N/A",
"└─Point_Get 1.00 root table:t handle:1",
))
tk.MustQuery("explain format = 'brief' select a from t where a = -1").Check(testkit.Rows(
"TableDual 0.00 root rows:0",
))
tk.MustExec(`set @@tidb_opt_fix_control = "52592:ON"`)
tk.MustQuery("explain format = 'brief' select * from t where a = 1").Check(testkit.Rows(
"TableReader 1.00 root data:TableRangeScan",
"└─TableRangeScan 1.00 cop[tikv] table:t range:[1,1], keep order:false, stats:pseudo",
))
tk.MustQuery("explain format = 'brief' select * from t where 1 = a").Check(testkit.Rows(
"TableReader 1.00 root data:TableRangeScan",
"└─TableRangeScan 1.00 cop[tikv] table:t range:[1,1], keep order:false, stats:pseudo",
))
tk.MustQuery("explain format = 'brief' update t set b=b+1, c=c+1 where a = 1").Check(testkit.Rows(
"Update N/A root N/A",
"└─TableReader 1.00 root data:TableRangeScan",
" └─TableRangeScan 1.00 cop[tikv] table:t range:[1,1], keep order:false, stats:pseudo",
))
tk.MustQuery("explain format = 'brief' delete from t where a = 1").Check(testkit.Rows(
"Delete N/A root N/A",
"└─TableReader 1.00 root data:TableRangeScan",
" └─TableRangeScan 1.00 cop[tikv] table:t range:[1,1], keep order:false, stats:pseudo",
))
tk.MustQuery("explain format = 'brief' select a from t where a = -1").Check(testkit.Rows(
"TableDual 0.00 root rows:0",
))
}

func TestIssue56832(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (id int primary key, c enum('0', '1', '2'));")
tk.MustExec("insert into t values (0,'0'), (1,'1'), (2,'2');")
tk.MustExec("update t set c = 2 where id = 0;")
tk.MustQuery("select c from t where id = 0").Check(testkit.Rows("1"))
}
>>>>>>> 1c059a1216d (planner: set enumsetasint if original value is int in point get (#57550))

0 comments on commit 63735c4

Please sign in to comment.