@@ -58,3 +58,31 @@ func TestIssue43461(t *testing.T) {
58
58
59
59
require .NotEqual (t , is .Columns , ts .Columns )
60
60
}
61
+
62
+ func Test53726 (t * testing.T ) {
63
+ // test for RemoveUnnecessaryFirstRow
64
+ store := testkit .CreateMockStore (t )
65
+ tk := testkit .NewTestKit (t , store )
66
+ tk .MustExec ("use test" )
67
+ tk .MustExec ("create table t7(c int); " )
68
+ tk .MustExec ("insert into t7 values (575932053), (-258025139);" )
69
+ tk .MustQuery ("select distinct cast(c as decimal), cast(c as signed) from t7" ).
70
+ Sort ().Check (testkit .Rows ("-258025139 -258025139" , "575932053 575932053" ))
71
+ tk .MustQuery ("explain select distinct cast(c as decimal), cast(c as signed) from t7" ).
72
+ Check (testkit .Rows (
73
+ "HashAgg_8 8000.00 root group by:Column#7, Column#8, funcs:firstrow(Column#7)->Column#3, funcs:firstrow(Column#8)->Column#4" ,
74
+ "└─TableReader_9 8000.00 root data:HashAgg_4" ,
75
+ " └─HashAgg_4 8000.00 cop[tikv] group by:cast(test.t7.c, bigint(22) BINARY), cast(test.t7.c, decimal(10,0) BINARY), " ,
76
+ " └─TableFullScan_7 10000.00 cop[tikv] table:t7 keep order:false, stats:pseudo" ))
77
+
78
+ tk .MustExec ("analyze table t7" )
79
+ tk .MustQuery ("select distinct cast(c as decimal), cast(c as signed) from t7" ).
80
+ Sort ().
81
+ Check (testkit .Rows ("-258025139 -258025139" , "575932053 575932053" ))
82
+ tk .MustQuery ("explain select distinct cast(c as decimal), cast(c as signed) from t7" ).
83
+ Check (testkit .Rows (
84
+ "HashAgg_6 2.00 root group by:Column#13, Column#14, funcs:firstrow(Column#11)->Column#3, funcs:firstrow(Column#12)->Column#4" ,
85
+ "└─Projection_12 2.00 root cast(test.t7.c, decimal(10,0) BINARY)->Column#11, cast(test.t7.c, bigint(22) BINARY)->Column#12, cast(test.t7.c, decimal(10,0) BINARY)->Column#13, cast(test.t7.c, bigint(22) BINARY)->Column#14" ,
86
+ " └─TableReader_11 2.00 root data:TableFullScan_10" ,
87
+ " └─TableFullScan_10 2.00 cop[tikv] table:t7 keep order:false" ))
88
+ }
0 commit comments