Skip to content

Commit 8e67c31

Browse files
authored
planner: set enumsetasint if original value is int in point get (#57550) (#59257)
close #56832
1 parent 73082a2 commit 8e67c31

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

planner/core/point_get_plan.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,11 @@ func buildOrderedList(ctx sessionctx.Context, plan Plan, list []*ast.Assignment,
16701670
if err != nil {
16711671
return nil, true
16721672
}
1673-
expr = expression.BuildCastFunction(ctx, expr, col.GetType())
1673+
castToTP := col.GetType()
1674+
if castToTP.GetType() == mysql.TypeEnum && assign.Expr.GetType().EvalType() == types.ETInt {
1675+
castToTP.AddFlag(mysql.EnumSetAsIntFlag)
1676+
}
1677+
expr = expression.BuildCastFunction(ctx, expr, castToTP)
16741678
if allAssignmentsAreConstant {
16751679
_, isConst := expr.(*expression.Constant)
16761680
allAssignmentsAreConstant = isConst

planner/core/point_get_plan_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,3 +993,14 @@ func TestIssue23511(t *testing.T) {
993993
tk.MustQuery("select * from t2 where col1 = 0x000039;").Check(testkit.Rows("\x009"))
994994
tk.MustExec("drop table t1, t2;")
995995
}
996+
997+
func TestIssue56832(t *testing.T) {
998+
store := testkit.CreateMockStore(t)
999+
tk := testkit.NewTestKit(t, store)
1000+
tk.MustExec("use test")
1001+
tk.MustExec("drop table if exists t")
1002+
tk.MustExec("create table t (id int primary key, c enum('0', '1', '2'));")
1003+
tk.MustExec("insert into t values (0,'0'), (1,'1'), (2,'2');")
1004+
tk.MustExec("update t set c = 2 where id = 0;")
1005+
tk.MustQuery("select c from t where id = 0").Check(testkit.Rows("1"))
1006+
}

0 commit comments

Comments
 (0)