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

types: fix incorrect return type about if function when argument type contains bit #27611

Closed
wants to merge 10 commits into from
Closed
2 changes: 1 addition & 1 deletion executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ func (s *testSuiteP2) TestUnion(c *C) {
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a bit(20), b float, c double, d int)")
tk.MustExec("insert into t values(10, 10, 10, 10), (1, -1, 2, -2), (2, -2, 1, 1), (2, 1.1, 2.1, 10.1)")
tk.MustQuery("select a from t union select 10 order by a").Check(testkit.Rows("1", "2", "10"))
tk.MustQuery("select a from t union select 10 order by a").Check(testkit.Rows("\x00\x00\x01", "\x00\x00\x02", "\x00\x00\n", "10"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why need change the test? Seems the old result same with mysql.

}

func (s *testSuite2) TestUnionLimit(c *C) {
Expand Down
15 changes: 15 additions & 0 deletions planner/core/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4028,6 +4028,21 @@ func (s *testIntegrationSerialSuite) TestIssue26250(c *C) {
tk.MustQuery("select * from tp,tn where tp.id=tn.id and tn.id=1 for update;").Check(testkit.Rows("1 1"))
}

func (s *testIntegrationSerialSuite) TestIssue26358(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("CREATE TABLE all_types (\n id int(11) NOT NULL,\n d_tinyint tinyint(4) DEFAULT NULL,\n d_smallint smallint(6) DEFAULT NULL,\n d_int int(11) DEFAULT NULL,\n d_bigint bigint(20) DEFAULT NULL,\n d_float float DEFAULT NULL,\n d_double double DEFAULT NULL,\n d_decimal decimal(10,2) DEFAULT NULL,\n d_bit bit(10) DEFAULT NULL,\n d_binary binary(10) DEFAULT NULL,\n d_date date DEFAULT NULL,\n d_datetime datetime DEFAULT NULL,\n d_timestamp timestamp NULL DEFAULT NULL,\n d_varchar varchar(20) NULL default NULL,\n PRIMARY KEY (id)\n);")
tk.MustExec("insert into all_types values(0, 0, 1, 2, 3, 1.5, 2.2, 10.23, 12, 'xy', '2021-12-12', '2021-12-12 12:00:00', '2021-12-12 12:00:00', '123');")
tk.MustQuery("select d_bit, d_smallint, if(d_bit, d_bit, d_smallint), if(d_bit, d_smallint, d_bit) from all_types;").Check(testkit.Rows("\x00\f 1 \x00\f 1"))
tk.MustQuery("select d_bit, d_tinyint, if(d_bit, d_bit, d_tinyint), if(d_bit, d_tinyint, d_bit) from all_types;").Check(testkit.Rows("\x00\f 0 \x00\f 0"))
tk.MustQuery("select d_bit, d_int, if(d_bit, d_bit, d_int), if(d_bit, d_int, d_bit) from all_types;").Check(testkit.Rows("\x00\f 2 \x00\f 2"))
tk.MustQuery("select d_bit, d_bigint, if(d_bit, d_bit, d_bigint), if(d_bit, d_bigint, d_bit) from all_types;").Check(testkit.Rows("\x00\f 3 \x00\f 3"))
tk.MustQuery("select d_bit, d_float, if(d_bit, d_bit, d_float), if(d_bit, d_float, d_bit) from all_types;").Check(testkit.Rows("\x00\f 1.5 \x00\f 1.5"))
tk.MustQuery("select d_bit, d_double, if(d_bit, d_bit, d_double), if(d_bit, d_double, d_bit) from all_types;").Check(testkit.Rows("\x00\f 2.2 \x00\f 2.2"))
tk.MustQuery("select d_bit, d_decimal, if(d_bit, d_bit, d_decimal), if(d_bit, d_decimal, d_bit) from all_types;").Check(testkit.Rows("\x00\f 10.23 12 10.23"))
tk.MustExec("drop table if exists all_types")
}

func (s *testIntegrationSuite) TestCorrelationAdjustment4Limit(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down
24 changes: 12 additions & 12 deletions types/field_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{
// mysql.TypeNewDate mysql.TypeVarchar
mysql.TypeVarchar, mysql.TypeVarchar,
// mysql.TypeBit <16>-<244>
mysql.TypeLonglong,
mysql.TypeVarchar,
// mysql.TypeJSON
mysql.TypeVarchar,
// mysql.TypeNewDecimal mysql.TypeEnum
Expand Down Expand Up @@ -441,7 +441,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{
// mysql.TypeNewDate mysql.TypeVarchar
mysql.TypeVarchar, mysql.TypeVarchar,
// mysql.TypeBit <16>-<244>
mysql.TypeLonglong,
mysql.TypeVarchar,
// mysql.TypeJSON
mysql.TypeVarchar,
// mysql.TypeNewDecimal mysql.TypeEnum
Expand Down Expand Up @@ -474,7 +474,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{
// mysql.TypeNewDate mysql.TypeVarchar
mysql.TypeVarchar, mysql.TypeVarchar,
// mysql.TypeBit <16>-<244>
mysql.TypeLonglong,
mysql.TypeVarchar,
// mysql.TypeJSON
mysql.TypeVarchar,
// mysql.TypeNewDecimal mysql.TypeEnum
Expand Down Expand Up @@ -507,7 +507,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{
// mysql.TypeNewDate mysql.TypeVarchar
mysql.TypeVarchar, mysql.TypeVarchar,
// mysql.TypeBit <16>-<244>
mysql.TypeDouble,
mysql.TypeVarchar,
// mysql.TypeJSON
mysql.TypeVarchar,
// mysql.TypeNewDecimal mysql.TypeEnum
Expand Down Expand Up @@ -540,7 +540,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{
// mysql.TypeNewDate mysql.TypeVarchar
mysql.TypeVarchar, mysql.TypeVarchar,
// mysql.TypeBit <16>-<244>
mysql.TypeDouble,
mysql.TypeVarchar,
// mysql.TypeJSON
mysql.TypeVarchar,
// mysql.TypeNewDecimal mysql.TypeEnum
Expand Down Expand Up @@ -639,7 +639,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{
// mysql.TypeNewDate mysql.TypeVarchar
mysql.TypeNewDate, mysql.TypeVarchar,
// mysql.TypeBit <16>-<244>
mysql.TypeLonglong,
mysql.TypeVarchar,
// mysql.TypeJSON
mysql.TypeVarchar,
// mysql.TypeNewDecimal mysql.TypeEnum
Expand Down Expand Up @@ -672,7 +672,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{
// mysql.TypeNewDate mysql.TypeVarchar
mysql.TypeNewDate, mysql.TypeVarchar,
// mysql.TypeBit <16>-<244>
mysql.TypeLonglong,
mysql.TypeVarchar,
// mysql.TypeJSON
mysql.TypeVarchar,
// mysql.TypeNewDecimal mysql.TypeEnum
Expand Down Expand Up @@ -887,15 +887,15 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{
/* mysql.TypeBit -> */
{
// mysql.TypeUnspecified mysql.TypeTiny
mysql.TypeVarchar, mysql.TypeLonglong,
mysql.TypeVarchar, mysql.TypeVarchar,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for these changes? Mysql's type merge is same with tidb.

// mysql.TypeShort mysql.TypeLong
mysql.TypeLonglong, mysql.TypeLonglong,
mysql.TypeVarchar, mysql.TypeVarchar,
// mysql.TypeFloat mysql.TypeDouble
mysql.TypeDouble, mysql.TypeDouble,
mysql.TypeVarchar, mysql.TypeVarchar,
// mysql.TypeNull mysql.TypeTimestamp
mysql.TypeBit, mysql.TypeVarchar,
// mysql.TypeLonglong mysql.TypeInt24
mysql.TypeLonglong, mysql.TypeLonglong,
mysql.TypeVarchar, mysql.TypeLonglong,
// mysql.TypeDate mysql.TypeTime
mysql.TypeVarchar, mysql.TypeVarchar,
// mysql.TypeDatetime mysql.TypeYear
Expand Down Expand Up @@ -969,7 +969,7 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{
// mysql.TypeNewDate mysql.TypeVarchar
mysql.TypeVarchar, mysql.TypeVarchar,
// mysql.TypeBit <16>-<244>
mysql.TypeNewDecimal,
mysql.TypeVarchar,
// mysql.TypeJSON
mysql.TypeVarchar,
// mysql.TypeNewDecimal mysql.TypeEnum
Expand Down
2 changes: 1 addition & 1 deletion types/field_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (s *testFieldTypeSuite) TestAggFieldType(c *C) {
mysql.TypeVarString, mysql.TypeGeometry:
c.Assert(aggTp.Tp, Equals, mysql.TypeVarchar)
case mysql.TypeBit:
c.Assert(aggTp.Tp, Equals, mysql.TypeLonglong)
c.Assert(aggTp.Tp, Equals, mysql.TypeVarchar)
case mysql.TypeString:
c.Assert(aggTp.Tp, Equals, mysql.TypeString)
case mysql.TypeUnspecified, mysql.TypeNewDecimal:
Expand Down