From 23089a6a85fd0b5fbd093e34751b92cff3947049 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Mon, 20 May 2024 16:13:29 +0800 Subject: [PATCH 1/3] fixup --- pkg/util/ranger/points.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/util/ranger/points.go b/pkg/util/ranger/points.go index 7f015e3f0385e..67d1b56fcc76c 100644 --- a/pkg/util/ranger/points.go +++ b/pkg/util/ranger/points.go @@ -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 large 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. From 6d6dba246a8bea015fa00985d076fd54400ac491 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Mon, 20 May 2024 16:15:51 +0800 Subject: [PATCH 2/3] fixup --- pkg/planner/core/integration_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/planner/core/integration_test.go b/pkg/planner/core/integration_test.go index 5c06840c2d4b0..01d8ccd2511b9 100644 --- a/pkg/planner/core/integration_test.go +++ b/pkg/planner/core/integration_test.go @@ -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) From 62ea29c3f0c5e46b62570c1ddbc81146f72a74b1 Mon Sep 17 00:00:00 2001 From: qw4990 Date: Mon, 20 May 2024 16:17:15 +0800 Subject: [PATCH 3/3] fixup --- pkg/util/ranger/points.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/util/ranger/points.go b/pkg/util/ranger/points.go index 67d1b56fcc76c..f01bfa89d97cf 100644 --- a/pkg/util/ranger/points.go +++ b/pkg/util/ranger/points.go @@ -330,7 +330,7 @@ func (r *builder) buildFromBinOp( } // If nulleq with null value, values.ToInt64 will return err if col.GetType().GetType() == mysql.TypeYear && !value.IsNull() { - // Convert the large uint number to int and then let the following logic can handle it correctly. + // 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)