Skip to content

Commit

Permalink
Merge master to v4.0 (pingcap#14898)
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala authored Feb 21, 2020
1 parent 511cedf commit 700d9de
Show file tree
Hide file tree
Showing 408 changed files with 24,592 additions and 8,430 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ tools/bin/golangci-lint:
# $ make vectorized-bench VB_FILE=Time VB_FUNC=builtinCurrentDateSig
vectorized-bench:
cd ./expression && \
go test -v -benchmem \
go test -v -timeout=0 -benchmem \
-bench=BenchmarkVectorizedBuiltin$(VB_FILE)Func \
-run=BenchmarkVectorizedBuiltin$(VB_FILE)Func \
-args "$(VB_FUNC)"
22 changes: 19 additions & 3 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (s *testSuite) TestGlobalBinding(c *C) {
metrics.BindTotalGauge.WithLabelValues(metrics.ScopeGlobal, bindinfo.Using).Write(pb)
c.Assert(pb.GetGauge().GetValue(), Equals, float64(1))
metrics.BindMemoryUsage.WithLabelValues(metrics.ScopeGlobal, bindinfo.Using).Write(pb)
c.Assert(pb.GetGauge().GetValue(), Equals, float64(121))
c.Assert(pb.GetGauge().GetValue(), Equals, float64(97))

sql, hash := parser.NormalizeDigest("select * from t where i > 30.0")

Expand Down Expand Up @@ -228,7 +228,7 @@ func (s *testSuite) TestGlobalBinding(c *C) {
c.Assert(pb.GetGauge().GetValue(), Equals, float64(0))
metrics.BindMemoryUsage.WithLabelValues(metrics.ScopeGlobal, bindinfo.Using).Write(pb)
// From newly created global bind handle.
c.Assert(pb.GetGauge().GetValue(), Equals, float64(121))
c.Assert(pb.GetGauge().GetValue(), Equals, float64(97))

bindHandle = bindinfo.NewBindHandle(tk.Se)
err = bindHandle.Update(true)
Expand Down Expand Up @@ -275,7 +275,7 @@ func (s *testSuite) TestSessionBinding(c *C) {
metrics.BindTotalGauge.WithLabelValues(metrics.ScopeSession, bindinfo.Using).Write(pb)
c.Assert(pb.GetGauge().GetValue(), Equals, float64(1))
metrics.BindMemoryUsage.WithLabelValues(metrics.ScopeSession, bindinfo.Using).Write(pb)
c.Assert(pb.GetGauge().GetValue(), Equals, float64(121))
c.Assert(pb.GetGauge().GetValue(), Equals, float64(97))

handle := tk.Se.Value(bindinfo.SessionBindInfoKeyType).(*bindinfo.SessionHandle)
bindData := handle.GetBindRecord("select * from t where i > ?", "test")
Expand Down Expand Up @@ -691,3 +691,19 @@ func (s *testSuite) TestOutdatedInfoSchema(c *C) {
tk.MustExec("truncate table mysql.bind_info")
tk.MustExec("create global binding for select * from t using select * from t use index(idx)")
}

func (s *testSuite) TestPrivileges(c *C) {
tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int, b int, index idx(a))")
tk.MustExec("create global binding for select * from t using select * from t use index(idx)")
c.Assert(tk.Se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil), IsTrue)
rows := tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
tk.MustExec("create user test@'%'")
c.Assert(tk.Se.Auth(&auth.UserIdentity{Username: "test", Hostname: "%"}, nil, nil), IsTrue)
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 0)
}
5 changes: 2 additions & 3 deletions cmd/explaintest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,9 +597,8 @@ func openDBWithRetry(driverName, dataSourceName string) (mdb *sql.DB, err error)
break
}
log.Warn("ping DB failed", zap.Int("retry count", i), zap.Error(err))
err = mdb.Close()
if err != nil {
log.Error("close DB failed", zap.Error(err))
if err1 := mdb.Close(); err1 != nil {
log.Error("close DB failed", zap.Error(err1))
}
time.Sleep(sleepTime)
}
Expand Down
57 changes: 0 additions & 57 deletions cmd/explaintest/r/access_tiflash.result

This file was deleted.

29 changes: 18 additions & 11 deletions cmd/explaintest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ create table t2 (c1 int unique, c2 int);
insert into t2 values(1, 0), (2, 1);
create table t3 (a bigint, b bigint, c bigint, d bigint);
create table t4 (a int, b int, c int, index idx(a, b), primary key(a));
create index expr_idx on t4((a+b+1));
set @@session.tidb_opt_agg_push_down = 1;
set @@session.tidb_opt_insubq_to_join_and_agg=1;
set @@session.tidb_hashagg_partial_concurrency = 1;
Expand Down Expand Up @@ -187,32 +188,38 @@ HashAgg_18 24000.00 root group by:Column#10, funcs:firstrow(Column#11)->Column#1
└─StreamAgg_60 8000.00 root group by:test.t2.c1, funcs:firstrow(test.t2.c1)->Column#11, funcs:firstrow(test.t2.c1)->Column#10
└─IndexReader_73 10000.00 root index:IndexScan_72
└─IndexScan_72 10000.00 cop[tikv] table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo
select * from information_schema.tidb_indexes where table_name='t4';
TABLE_SCHEMA TABLE_NAME NON_UNIQUE KEY_NAME SEQ_IN_INDEX COLUMN_NAME SUB_PART INDEX_COMMENT Expression INDEX_ID
test t4 0 PRIMARY 1 a NULL NULL 0
test t4 1 idx 1 a NULL NULL 1
test t4 1 idx 2 b NULL NULL 1
test t4 1 expr_idx 1 NULL NULL (`a` + `b` + 1) 2
explain select count(1) from (select count(1) from (select * from t1 where c3 = 100) k) k2;
id count task operator info
StreamAgg_13 1.00 root funcs:count(1)->Column#5
└─StreamAgg_28 1.00 root funcs:firstrow(Column#8)->Column#6
└─StreamAgg_28 1.00 root funcs:firstrow(Column#9)->Column#7
└─TableReader_29 1.00 root data:StreamAgg_17
└─StreamAgg_17 1.00 cop[tikv] funcs:firstrow(1)->Column#8
└─StreamAgg_17 1.00 cop[tikv] funcs:firstrow(1)->Column#9
└─Selection_27 10.00 cop[tikv] eq(test.t1.c3, 100)
└─TableScan_26 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain select 1 from (select count(c2), count(c3) from t1) k;
id count task operator info
Projection_5 1.00 root 1->Column#6
└─StreamAgg_21 1.00 root funcs:firstrow(Column#13)->Column#7
└─StreamAgg_21 1.00 root funcs:firstrow(Column#14)->Column#9
└─TableReader_22 1.00 root data:StreamAgg_9
└─StreamAgg_9 1.00 cop[tikv] funcs:firstrow(1)->Column#13
└─StreamAgg_9 1.00 cop[tikv] funcs:firstrow(1)->Column#14
└─TableScan_19 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain select count(1) from (select max(c2), count(c3) as m from t1) k;
id count task operator info
StreamAgg_11 1.00 root funcs:count(1)->Column#6
└─StreamAgg_27 1.00 root funcs:firstrow(Column#12)->Column#7
└─StreamAgg_27 1.00 root funcs:firstrow(Column#13)->Column#8
└─TableReader_28 1.00 root data:StreamAgg_15
└─StreamAgg_15 1.00 cop[tikv] funcs:firstrow(1)->Column#12
└─StreamAgg_15 1.00 cop[tikv] funcs:firstrow(1)->Column#13
└─TableScan_25 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
explain select count(1) from (select count(c2) from t1 group by c3) k;
id count task operator info
StreamAgg_11 1.00 root funcs:count(1)->Column#5
└─HashAgg_22 8000.00 root group by:test.t1.c3, funcs:firstrow(1)->Column#6
└─HashAgg_22 8000.00 root group by:test.t1.c3, funcs:firstrow(1)->Column#7
└─TableReader_19 10000.00 root data:TableScan_18
└─TableScan_18 10000.00 cop[tikv] table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
set @@session.tidb_opt_insubq_to_join_and_agg=0;
Expand Down Expand Up @@ -498,15 +505,15 @@ PRIMARY KEY (`id`)
EXPLAIN SELECT COUNT(1) FROM (SELECT COALESCE(b.region_name, '不详') region_name, SUM(a.registration_num) registration_num FROM (SELECT stat_date, show_date, region_id, 0 registration_num FROM test01 WHERE period = 1 AND stat_date >= 20191202 AND stat_date <= 20191202 UNION ALL SELECT stat_date, show_date, region_id, registration_num registration_num FROM test01 WHERE period = 1 AND stat_date >= 20191202 AND stat_date <= 20191202) a LEFT JOIN test02 b ON a.region_id = b.id WHERE registration_num > 0 AND a.stat_date >= '20191202' AND a.stat_date <= '20191202' GROUP BY a.stat_date , a.show_date , COALESCE(b.region_name, '不详') ) JLS;
id count task operator info
StreamAgg_22 1.00 root funcs:count(1)->Column#22
└─HashAgg_25 1.00 root group by:Column#31, Column#32, Column#33, funcs:firstrow(1)->Column#23
└─Projection_48 0.02 root Column#14, Column#15, coalesce(test.test02.region_name, 不详)->Column#33
└─HashAgg_25 1.00 root group by:Column#30, Column#31, Column#32, funcs:firstrow(1)->Column#29
└─Projection_48 0.02 root Column#14, Column#15, coalesce(test.test02.region_name, 不详)->Column#32
└─IndexMergeJoin_32 0.02 root left outer join, inner:TableReader_30, outer key:Column#16, inner key:test.test02.id
├─Union_37 0.02 root
│ ├─Projection_38 0.01 root test.test01.stat_date, test.test01.show_date, test.test01.region_id, cast(0)->Column#17
│ ├─Projection_38 0.01 root test.test01.stat_date, test.test01.show_date, test.test01.region_id
│ │ └─TableReader_41 0.01 root data:Selection_40
│ │ └─Selection_40 0.01 cop[tikv] eq(test.test01.period, 1), ge(test.test01.stat_date, 20191202), ge(test.test01.stat_date, 20191202), gt(cast(0), 0), le(test.test01.stat_date, 20191202), le(test.test01.stat_date, 20191202)
│ │ └─TableScan_39 10000.00 cop[tikv] table:test01, range:[-inf,+inf], keep order:false, stats:pseudo
│ └─Projection_42 0.01 root test.test01.stat_date, test.test01.show_date, test.test01.region_id, cast(test.test01.registration_num)->Column#17
│ └─Projection_42 0.01 root test.test01.stat_date, test.test01.show_date, test.test01.region_id
│ └─TableReader_45 0.01 root data:Selection_44
│ └─Selection_44 0.01 cop[tikv] eq(test.test01.period, 1), ge(test.test01.stat_date, 20191202), ge(test.test01.stat_date, 20191202), gt(cast(test.test01.registration_num), 0), le(test.test01.stat_date, 20191202), le(test.test01.stat_date, 20191202)
│ └─TableScan_43 10000.00 cop[tikv] table:test01, range:[-inf,+inf], keep order:false, stats:pseudo
Expand Down
Loading

0 comments on commit 700d9de

Please sign in to comment.