Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: fix incompatible behaviors between prep and non-prep statements when converting date/time values (#42443) #46710

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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