Skip to content

Commit

Permalink
planner: fix the wrong result caused by `year_col cmp out-of-range-ui…
Browse files Browse the repository at this point in the history
  • Loading branch information
qw4990 authored and RidRisR committed May 23, 2024
1 parent 7afa44a commit 5265b56
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit 5265b56

Please sign in to comment.