Skip to content

Commit 4ec892c

Browse files
authored
planner: fix the wrong result caused by year_col cmp out-of-range-uint (#53395) (#55105)
close #50235
1 parent 2cdf91f commit 4ec892c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pkg/planner/core/integration_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,15 @@ func TestRepeatPushDownToTiFlash(t *testing.T) {
12431243
tk.MustQuery("explain select repeat(a,b) from t;").CheckAt([]int{0, 2, 4}, rows)
12441244
}
12451245

1246+
func TestIssue50235(t *testing.T) {
1247+
store := testkit.CreateMockStore(t)
1248+
tk := testkit.NewTestKit(t, store)
1249+
tk.MustExec(`use test`)
1250+
tk.MustExec(`create table tt (c year(4) NOT NULL DEFAULT '2016', primary key(c));`)
1251+
tk.MustExec(`insert into tt values (2016);`)
1252+
tk.MustQuery(`select * from tt where c < 16212511333665770580`).Check(testkit.Rows("2016"))
1253+
}
1254+
12461255
func TestIssue36194(t *testing.T) {
12471256
store, dom := testkit.CreateMockStoreAndDomain(t)
12481257
tk := testkit.NewTestKit(t, store)

pkg/util/ranger/points.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,12 @@ func (r *builder) buildFromBinOp(
330330
}
331331
// If nulleq with null value, values.ToInt64 will return err
332332
if col.GetType().GetType() == mysql.TypeYear && !value.IsNull() {
333+
// Convert the out-of-range uint number to int and then let the following logic can handle it correctly.
334+
// Since the max value of year is 2155, `col op MaxUint` should have the same result with `col op MaxInt`.
335+
if value.Kind() == types.KindUint64 && value.GetUint64() > math.MaxInt64 {
336+
value.SetInt64(math.MaxInt64)
337+
}
338+
333339
// If the original value is adjusted, we need to change the condition.
334340
// For example, col < 2156. Since the max year is 2155, 2156 is changed to 2155.
335341
// col < 2155 is wrong. It should be col <= 2155.

0 commit comments

Comments
 (0)