Skip to content

Commit

Permalink
planner: fix incompatible behaviors between prep and non-prep stateme…
Browse files Browse the repository at this point in the history
…nts when converting date/time values (#42443) (#46710)

close #42439
  • Loading branch information
ti-chi-bot authored Oct 16, 2023
1 parent 6bf0542 commit dfa2b6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions planner/core/prepare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,19 @@ func TestIssue33067(t *testing.T) {
tk.MustQuery("select @@last_plan_from_cache").Check(testkit.Rows("0"))
}

func TestIssue42439(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)
tk.MustExec(`CREATE TABLE UK_MU16407 (COL3 timestamp NULL DEFAULT NULL, UNIQUE KEY U3(COL3))`)
tk.MustExec(`insert into UK_MU16407 values("1985-08-31 18:03:27")`)
tk.MustExec(`PREPARE st FROM 'SELECT COL3 FROM UK_MU16407 WHERE COL3>?'`)
tk.MustExec(`set @a='2039-1-19 3:14:40'`)
tk.MustExec(`execute st using @a`) // no error
tk.MustExec(`set @a='1950-1-19 3:14:40'`)
tk.MustQuery(`execute st using @a`).Check(testkit.Rows(`1985-08-31 18:03:27`))
}

func TestIssue29486(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down
4 changes: 2 additions & 2 deletions util/ranger/ranger.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ func convertPoint(sctx sessionctx.Context, point *point, tp *types.FieldType) (*
casted, err := point.value.ConvertTo(sc, tp)
if err != nil {
if sctx.GetSessionVars().StmtCtx.InPreparedPlanBuilding {
// do not ignore these errors if in prepared plan building for safety
return nil, errors.Trace(err)
// skip plan cache in this case for safety.
sctx.GetSessionVars().StmtCtx.SetSkipPlanCache(errors.Errorf("%s when converting %v", err.Error(), point.value))
}
//revive:disable:empty-block
if tp.GetType() == mysql.TypeYear && terror.ErrorEqual(err, types.ErrWarnDataOutOfRange) {
Expand Down

0 comments on commit dfa2b6f

Please sign in to comment.