Skip to content

Commit

Permalink
planner: set enumsetasint if original value is int in point get (#57550)
Browse files Browse the repository at this point in the history
close #56832
  • Loading branch information
xhebox authored Nov 21, 2024
1 parent e4e707d commit 1c059a1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/planner/core/point_get_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,11 @@ func buildOrderedList(ctx base.PlanContext, plan base.Plan, list []*ast.Assignme
if err != nil {
return nil, true
}
expr = expression.BuildCastFunction(ctx.GetExprCtx(), expr, col.GetStaticType())
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)
if allAssignmentsAreConstant {
_, isConst := expr.(*expression.Constant)
allAssignmentsAreConstant = isConst
Expand Down
11 changes: 11 additions & 0 deletions pkg/planner/core/point_get_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,14 @@ func TestIssue52592(t *testing.T) {
"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"))
}

0 comments on commit 1c059a1

Please sign in to comment.