Skip to content

Commit 1c059a1

Browse files
authored
planner: set enumsetasint if original value is int in point get (#57550)
close #56832
1 parent e4e707d commit 1c059a1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pkg/planner/core/point_get_plan.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2007,7 +2007,11 @@ func buildOrderedList(ctx base.PlanContext, plan base.Plan, list []*ast.Assignme
20072007
if err != nil {
20082008
return nil, true
20092009
}
2010-
expr = expression.BuildCastFunction(ctx.GetExprCtx(), expr, col.GetStaticType())
2010+
castToTP := col.GetStaticType()
2011+
if castToTP.GetType() == mysql.TypeEnum && assign.Expr.GetType().EvalType() == types.ETInt {
2012+
castToTP.AddFlag(mysql.EnumSetAsIntFlag)
2013+
}
2014+
expr = expression.BuildCastFunction(ctx.GetExprCtx(), expr, castToTP)
20112015
if allAssignmentsAreConstant {
20122016
_, isConst := expr.(*expression.Constant)
20132017
allAssignmentsAreConstant = isConst

pkg/planner/core/point_get_plan_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,3 +275,14 @@ func TestIssue52592(t *testing.T) {
275275
"TableDual 0.00 root rows:0",
276276
))
277277
}
278+
279+
func TestIssue56832(t *testing.T) {
280+
store := testkit.CreateMockStore(t)
281+
tk := testkit.NewTestKit(t, store)
282+
tk.MustExec("use test")
283+
tk.MustExec("drop table if exists t")
284+
tk.MustExec("create table t (id int primary key, c enum('0', '1', '2'));")
285+
tk.MustExec("insert into t values (0,'0'), (1,'1'), (2,'2');")
286+
tk.MustExec("update t set c = 2 where id = 0;")
287+
tk.MustQuery("select c from t where id = 0").Check(testkit.Rows("1"))
288+
}

0 commit comments

Comments
 (0)