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 the wrong result caused by year_col cmp out-of-range-uint #53395

Merged
merged 3 commits into from
May 20, 2024
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
9 changes: 9 additions & 0 deletions pkg/planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,6 +1218,15 @@ func TestRepeatPushDownToTiFlash(t *testing.T) {
tk.MustQuery("explain select repeat(a,b) from t;").CheckAt([]int{0, 2, 4}, rows)
}

func TestIssue50235(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)
tk.MustExec(`create table tt (c year(4) NOT NULL DEFAULT '2016', primary key(c));`)
tk.MustExec(`insert into tt values (2016);`)
tk.MustQuery(`select * from tt where c < 16212511333665770580`).Check(testkit.Rows("2016"))
}

func TestIssue36194(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
tk := testkit.NewTestKit(t, store)
Expand Down
6 changes: 6 additions & 0 deletions pkg/util/ranger/points.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ func (r *builder) buildFromBinOp(
}
// If nulleq with null value, values.ToInt64 will return err
if col.GetType().GetType() == mysql.TypeYear && !value.IsNull() {
// Convert the out-of-range uint number to int and then let the following logic can handle it correctly.
// Since the max value of year is 2155, `col op MaxUint` should have the same result with `col op MaxInt`.
if value.Kind() == types.KindUint64 && value.GetUint64() > math.MaxInt64 {
value.SetInt64(math.MaxInt64)
}

// If the original value is adjusted, we need to change the condition.
// For example, col < 2156. Since the max year is 2155, 2156 is changed to 2155.
// col < 2155 is wrong. It should be col <= 2155.
Expand Down