diff --git a/expression/builtin_compare.go b/expression/builtin_compare.go index e2696356e2..5053454731 100644 --- a/expression/builtin_compare.go +++ b/expression/builtin_compare.go @@ -1092,6 +1092,8 @@ func getBaseCmpType(lhs, rhs types.EvalType, lft, rft *types.FieldType) types.Ev return types.ETString } else if (lhs == types.ETInt || (lft != nil && lft.Hybrid())) && (rhs == types.ETInt || (rft != nil && rft.Hybrid())) { return types.ETInt + } else if (lhs == types.ETDecimal && rhs == types.ETString) || (lhs == types.ETString && rhs == types.ETDecimal) { + return types.ETReal } else if ((lhs == types.ETInt || (lft != nil && lft.Hybrid())) || lhs == types.ETDecimal) && ((rhs == types.ETInt || (rft != nil && rft.Hybrid())) || rhs == types.ETDecimal) { return types.ETDecimal diff --git a/expression/integration_test.go b/expression/integration_test.go index b3242e1027..c61ac3f38f 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -8392,6 +8392,19 @@ func (s *testIntegrationSuite) TestIssue12205(c *C) { testkit.Rows("Warning 1292 Truncated incorrect time value: '18446744072635875000'")) } +// for issue 20128 +func (s *testIntegrationSerialSuite) TestIssue20128(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t;") + tk.MustExec("create table t(b enum('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') DEFAULT NULL, c decimal(40,20));") + tk.MustExec("insert into t values('z', 19.18040000000000000000);") + tk.MustExec("insert into t values('z', 26.18040000000000000000);") + tk.MustExec("insert into t values('z', 25.18040000000000000000);") + tk.MustQuery("select * from t where t.b > t.c;").Check(testkit.Rows("z 19.18040000000000000000", "z 25.18040000000000000000")) + tk.MustQuery("select * from t where t.b < t.c;").Check(testkit.Rows("z 26.18040000000000000000")) +} + func (s *testIntegrationSuite) TestIssue21677(c *C) { tk := testkit.NewTestKit(c, s.store)