Skip to content

Commit

Permalink
Merge branch 'release-4.0' into release-4.0-f22ec62dd03f
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhuang2016 authored Jan 28, 2021
2 parents e938186 + 1f5b303 commit 7a36064
Show file tree
Hide file tree
Showing 59 changed files with 2,456 additions and 487 deletions.
Binary file removed cmd/explaintest/portgenerator
Binary file not shown.
75 changes: 72 additions & 3 deletions cmd/explaintest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,9 @@ drop table if exists t;
create table t(a int, b int, c int);
explain select * from (select * from t order by (select 2)) t order by a, b;
id estRows task access object operator info
Sort_12 10000.00 root test.t.a:asc, test.t.b:asc
└─TableReader_18 10000.00 root data:TableFullScan_17
└─TableFullScan_17 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
Sort_13 10000.00 root test.t.a:asc, test.t.b:asc
└─TableReader_19 10000.00 root data:TableFullScan_18
└─TableFullScan_18 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
explain select * from (select * from t order by c) t order by a, b;
id estRows task access object operator info
Sort_6 10000.00 root test.t.a:asc, test.t.b:asc
Expand Down Expand Up @@ -784,3 +784,72 @@ Update_4 N/A root N/A
├─IndexRangeScan_9(Build) 0.10 cop[tikv] table:t, index:a(a, b) range:["[250 52 225 9 60 180 40 72 87 52 227 145 127 0 0 0]" "xb","[250 52 225 9 60 180 40 72 87 52 227 145 127 0 0 0]" "xb"], keep order:false, stats:pseudo
└─TableRowIDScan_10(Probe) 0.10 cop[tikv] table:t keep order:false, stats:pseudo
drop table if exists t;
create table t(a int, b int);
explain select (select count(n.a) from t) from t n;
id estRows task access object operator info
Projection_9 1.00 root Column#8
└─Apply_11 1.00 root CARTESIAN left outer join
├─StreamAgg_23(Build) 1.00 root funcs:count(Column#13)->Column#7
│ └─TableReader_24 1.00 root data:StreamAgg_15
│ └─StreamAgg_15 1.00 cop[tikv] funcs:count(test.t.a)->Column#13
│ └─TableFullScan_22 10000.00 cop[tikv] table:n keep order:false, stats:pseudo
└─MaxOneRow_27(Probe) 1.00 root
└─Projection_28 2.00 root Column#7
└─TableReader_30 2.00 root data:TableFullScan_29
└─TableFullScan_29 2.00 cop[tikv] table:t keep order:false, stats:pseudo
explain select (select sum((select count(a)))) from t;
id estRows task access object operator info
Projection_23 1.00 root Column#7
└─Apply_25 1.00 root CARTESIAN left outer join
├─StreamAgg_37(Build) 1.00 root funcs:count(Column#15)->Column#5
│ └─TableReader_38 1.00 root data:StreamAgg_29
│ └─StreamAgg_29 1.00 cop[tikv] funcs:count(test.t.a)->Column#15
│ └─TableFullScan_36 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
└─HashAgg_43(Probe) 1.00 root funcs:sum(Column#12)->Column#7
└─HashJoin_44 1.00 root CARTESIAN left outer join
├─HashAgg_49(Build) 1.00 root group by:1, funcs:sum(Column#16)->Column#12
│ └─Projection_54 1.00 root cast(Column#6, decimal(65,0) BINARY)->Column#16
│ └─MaxOneRow_50 1.00 root
│ └─Projection_51 1.00 root Column#5
│ └─TableDual_52 1.00 root rows:1
└─TableDual_46(Probe) 1.00 root rows:1
explain select count(a) from t group by b order by (select count(a));
id estRows task access object operator info
Projection_11 8000.00 root Column#4
└─Sort_12 8000.00 root Column#5:asc
└─Apply_15 8000.00 root CARTESIAN left outer join
├─HashAgg_20(Build) 8000.00 root group by:test.t.b, funcs:count(Column#9)->Column#4
│ └─TableReader_21 8000.00 root data:HashAgg_16
│ └─HashAgg_16 8000.00 cop[tikv] group by:test.t.b, funcs:count(test.t.a)->Column#9
│ └─TableFullScan_19 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
└─MaxOneRow_24(Probe) 1.00 root
└─Projection_25 1.00 root Column#4
└─TableDual_26 1.00 root rows:1
explain select (select sum(count(a))) from t;
id estRows task access object operator info
Projection_11 1.00 root Column#5
└─Apply_13 1.00 root CARTESIAN left outer join
├─StreamAgg_25(Build) 1.00 root funcs:count(Column#8)->Column#4
│ └─TableReader_26 1.00 root data:StreamAgg_17
│ └─StreamAgg_17 1.00 cop[tikv] funcs:count(test.t.a)->Column#8
│ └─TableFullScan_24 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
└─StreamAgg_32(Probe) 1.00 root funcs:sum(Column#9)->Column#5
└─Projection_39 1.00 root cast(Column#4, decimal(65,0) BINARY)->Column#9
└─TableDual_37 1.00 root rows:1
explain select sum(a), (select sum(a)), count(a) from t group by b order by (select count(a));
id estRows task access object operator info
Projection_16 8000.00 root Column#4, Column#6, Column#5
└─Sort_17 8000.00 root Column#7:asc
└─Apply_20 8000.00 root CARTESIAN left outer join
├─Apply_22(Build) 8000.00 root CARTESIAN left outer join
│ ├─HashAgg_27(Build) 8000.00 root group by:test.t.b, funcs:sum(Column#16)->Column#4, funcs:count(Column#17)->Column#5
│ │ └─TableReader_28 8000.00 root data:HashAgg_23
│ │ └─HashAgg_23 8000.00 cop[tikv] group by:test.t.b, funcs:sum(test.t.a)->Column#16, funcs:count(test.t.a)->Column#17
│ │ └─TableFullScan_26 10000.00 cop[tikv] table:t keep order:false, stats:pseudo
│ └─MaxOneRow_31(Probe) 1.00 root
│ └─Projection_32 1.00 root Column#4
│ └─TableDual_33 1.00 root rows:1
└─MaxOneRow_34(Probe) 1.00 root
└─Projection_35 1.00 root Column#5
└─TableDual_36 1.00 root rows:1
drop table if exists t;
8 changes: 4 additions & 4 deletions cmd/explaintest/r/tpch.result
Original file line number Diff line number Diff line change
Expand Up @@ -711,10 +711,10 @@ and n_name = 'MOZAMBIQUE'
order by
value desc;
id estRows task access object operator info
Projection_52 1304801.67 root tpch.partsupp.ps_partkey, Column#18
└─Sort_53 1304801.67 root Column#18:desc
└─Selection_55 1304801.67 root gt(Column#18, NULL)
└─HashAgg_58 1631002.09 root group by:Column#44, funcs:sum(Column#42)->Column#18, funcs:firstrow(Column#43)->tpch.partsupp.ps_partkey
Projection_52 1304801.67 root tpch.partsupp.ps_partkey, Column#35
└─Sort_53 1304801.67 root Column#35:desc
└─Selection_55 1304801.67 root gt(Column#35, NULL)
└─HashAgg_58 1631002.09 root group by:Column#44, funcs:sum(Column#42)->Column#35, funcs:firstrow(Column#43)->tpch.partsupp.ps_partkey
└─Projection_79 1631002.09 root mul(tpch.partsupp.ps_supplycost, cast(tpch.partsupp.ps_availqty, decimal(20,0) BINARY))->Column#42, tpch.partsupp.ps_partkey, tpch.partsupp.ps_partkey
└─HashJoin_62 1631002.09 root inner join, equal:[eq(tpch.supplier.s_suppkey, tpch.partsupp.ps_suppkey)]
├─HashJoin_70(Build) 20000.00 root inner join, equal:[eq(tpch.nation.n_nationkey, tpch.supplier.s_nationkey)]
Expand Down
8 changes: 8 additions & 0 deletions cmd/explaintest/t/explain_easy.test
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,11 @@ create table t(a binary(16) not null, b varchar(2) default null, c varchar(100)
explain select * from t where a=x'FA34E1093CB428485734E3917F000000' and b='xb';
explain update t set c = 'ssss' where a=x'FA34E1093CB428485734E3917F000000' and b='xb';
drop table if exists t;

create table t(a int, b int);
explain select (select count(n.a) from t) from t n;
explain select (select sum((select count(a)))) from t;
explain select count(a) from t group by b order by (select count(a));
explain select (select sum(count(a))) from t;
explain select sum(a), (select sum(a)), count(a) from t group by b order by (select count(a));
drop table if exists t;
29 changes: 23 additions & 6 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/admin"
"github.com/pingcap/tidb/util/collate"
"github.com/pingcap/tidb/util/domainutil"
"github.com/pingcap/tidb/util/israce"
"github.com/pingcap/tidb/util/mock"
Expand Down Expand Up @@ -2205,19 +2206,35 @@ func (s *testDBSuite1) TestCreateTable(c *C) {
s.tk.MustExec("use test")
failSQL := "create table t_enum (a enum('e','e'));"
s.tk.MustGetErrCode(failSQL, errno.ErrDuplicatedValueInType)
failSQL = "create table t_enum (a enum('e','E'));"
}

func (s *testSerialDBSuite) TestCreateTableWithCollation(c *C) {
collate.SetNewCollationEnabledForTest(true)
defer collate.SetNewCollationEnabledForTest(false)
s.tk.MustExec("use test")
failSQL := "create table t_enum (a enum('e','E')) charset=utf8 collate=utf8_general_ci;"
s.tk.MustGetErrCode(failSQL, errno.ErrDuplicatedValueInType)
failSQL = "create table t_enum (a enum('abc','Abc')) charset=utf8 collate=utf8_general_ci;"
s.tk.MustGetErrCode(failSQL, errno.ErrDuplicatedValueInType)
failSQL = "create table t_enum (a enum('abc','Abc'));"
failSQL = "create table t_enum (a enum('e','E')) charset=utf8 collate=utf8_unicode_ci;"
s.tk.MustGetErrCode(failSQL, errno.ErrDuplicatedValueInType)
failSQL = "create table t_enum (a enum('ss','ß')) charset=utf8 collate=utf8_unicode_ci;"
s.tk.MustGetErrCode(failSQL, errno.ErrDuplicatedValueInType)
// test for set column
failSQL = "create table t_enum (a set('e','e'));"
s.tk.MustGetErrCode(failSQL, errno.ErrDuplicatedValueInType)
failSQL = "create table t_enum (a set('e','E'));"
failSQL = "create table t_enum (a set('e','E')) charset=utf8 collate=utf8_general_ci;"
s.tk.MustGetErrCode(failSQL, errno.ErrDuplicatedValueInType)
failSQL = "create table t_enum (a set('abc','Abc')) charset=utf8 collate=utf8_general_ci;"
s.tk.MustGetErrCode(failSQL, errno.ErrDuplicatedValueInType)
_, err := s.tk.Exec("create table t_enum (a enum('B','b')) charset=utf8 collate=utf8_general_ci;")
c.Assert(err.Error(), Equals, "[types:1291]Column 'a' has duplicated value 'b' in ENUM")
failSQL = "create table t_enum (a set('e','E')) charset=utf8 collate=utf8_unicode_ci;"
s.tk.MustGetErrCode(failSQL, errno.ErrDuplicatedValueInType)
failSQL = "create table t_enum (a set('abc','Abc'));"
failSQL = "create table t_enum (a set('ss','ß')) charset=utf8 collate=utf8_unicode_ci;"
s.tk.MustGetErrCode(failSQL, errno.ErrDuplicatedValueInType)
_, err = s.tk.Exec("create table t_enum (a enum('B','b'));")
c.Assert(err.Error(), Equals, "[types:1291]Column 'a' has duplicated value 'B' in ENUM")
_, err = s.tk.Exec("create table t_enum (a enum('ss','ß')) charset=utf8 collate=utf8_unicode_ci;")
c.Assert(err.Error(), Equals, "[types:1291]Column 'a' has duplicated value 'ß' in ENUM")
}

func (s *testDBSuite5) TestRepairTable(c *C) {
Expand Down
11 changes: 11 additions & 0 deletions executor/collation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ func (s *testCollationSuite) TestVecGroupChecker(c *C) {
}
c.Assert(groupChecker.isExhausted(), IsTrue)

tp.Collate = "utf8_unicode_ci"
groupChecker.reset()
_, err = groupChecker.splitIntoGroups(chk)
c.Assert(err, IsNil)
for i := 0; i < 3; i++ {
b, e := groupChecker.getNextGroup()
c.Assert(b, Equals, i*2)
c.Assert(e, Equals, i*2+2)
}
c.Assert(groupChecker.isExhausted(), IsTrue)

// test padding
tp.Collate = "utf8_bin"
tp.Flen = 6
Expand Down
13 changes: 13 additions & 0 deletions executor/memtable_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,19 @@ func (s *testMemTableReaderSuite) TestTiDBClusterLog(c *C) {
{"2019/08/26 06:27:17.011", "pd", "critical", "[test log message pd 14, bar]"},
},
},
{
conditions: []string{
"time>='2019/08/26 06:18:13.011'",
"time<='2099/08/26 06:28:19.011'",
// this pattern verifies that there is no optimization breaking
// length of multiple wildcards, for example, %% may be
// converted to %, but %_ cannot be converted to %.
"message like '%tidb_%_4%'",
},
expected: [][]string{
{"2019/08/26 06:25:17.011", "tidb", "critical", "[test log message tidb 14, bar]"},
},
},
}

var servers []string
Expand Down
8 changes: 4 additions & 4 deletions executor/testdata/agg_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@
"Name": "TestIssue12759HashAggCalledByApply",
"Cases": [
[
"Projection_28 1.00 root Column#3, Column#6, Column#9, Column#12",
"Projection_28 1.00 root Column#9, Column#10, Column#11, Column#12",
"└─Apply_30 1.00 root CARTESIAN left outer join",
" ├─Apply_32(Build) 1.00 root CARTESIAN left outer join",
" │ ├─Apply_34(Build) 1.00 root CARTESIAN left outer join",
" │ │ ├─HashAgg_39(Build) 1.00 root funcs:sum(Column#22)->Column#3, funcs:firstrow(Column#23)->test.test.a",
" │ │ ├─HashAgg_39(Build) 1.00 root funcs:sum(Column#22)->Column#9, funcs:firstrow(Column#23)->test.test.a",
" │ │ │ └─TableReader_40 1.00 root data:HashAgg_35",
" │ │ │ └─HashAgg_35 1.00 cop[tikv] funcs:sum(test.test.a)->Column#22, funcs:firstrow(test.test.a)->Column#23",
" │ │ │ └─TableFullScan_38 10000.00 cop[tikv] table:tt keep order:false, stats:pseudo",
" │ │ └─Projection_43(Probe) 1.00 root <nil>->Column#6",
" │ │ └─Projection_43(Probe) 1.00 root <nil>->Column#10",
" │ │ └─Limit_44 1.00 root offset:0, count:1",
" │ │ └─TableReader_50 1.00 root data:Limit_49",
" │ │ └─Limit_49 1.00 cop[tikv] offset:0, count:1",
" │ │ └─Selection_48 1.00 cop[tikv] eq(test.test.a, test.test.a)",
" │ │ └─TableFullScan_47 1000.00 cop[tikv] table:test keep order:false, stats:pseudo",
" │ └─Projection_54(Probe) 1.00 root <nil>->Column#9",
" │ └─Projection_54(Probe) 1.00 root <nil>->Column#11",
" │ └─Limit_55 1.00 root offset:0, count:1",
" │ └─TableReader_61 1.00 root data:Limit_60",
" │ └─Limit_60 1.00 cop[tikv] offset:0, count:1",
Expand Down
Loading

0 comments on commit 7a36064

Please sign in to comment.