Skip to content

Commit 0915912

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

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
@@ -1730,7 +1730,11 @@ func buildOrderedList(ctx sessionctx.Context, plan Plan, list []*ast.Assignment,
17301730
if err != nil {
17311731
return nil, true
17321732
}
1733-
expr = expression.BuildCastFunction(ctx, expr, col.GetType())
1733+
castToTP := col.GetType()
1734+
if castToTP.GetType() == mysql.TypeEnum && assign.Expr.GetType().EvalType() == types.ETInt {
1735+
castToTP.AddFlag(mysql.EnumSetAsIntFlag)
1736+
}
1737+
expr = expression.BuildCastFunction(ctx, expr, castToTP)
17341738
if allAssignmentsAreConstant {
17351739
_, isConst := expr.(*expression.Constant)
17361740
allAssignmentsAreConstant = isConst

pkg/planner/core/point_get_plan_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,14 @@ func TestIssue18042(t *testing.T) {
272272
require.Equal(t, uint64(100), tk.Session().GetSessionVars().StmtCtx.MaxExecutionTime)
273273
tk.MustExec("drop table t")
274274
}
275+
276+
func TestIssue56832(t *testing.T) {
277+
store := testkit.CreateMockStore(t)
278+
tk := testkit.NewTestKit(t, store)
279+
tk.MustExec("use test")
280+
tk.MustExec("drop table if exists t")
281+
tk.MustExec("create table t (id int primary key, c enum('0', '1', '2'));")
282+
tk.MustExec("insert into t values (0,'0'), (1,'1'), (2,'2');")
283+
tk.MustExec("update t set c = 2 where id = 0;")
284+
tk.MustQuery("select c from t where id = 0").Check(testkit.Rows("1"))
285+
}

0 commit comments

Comments
 (0)