Skip to content

Commit

Permalink
Merge branch 'release-2.1' of https://github.com/pingcap/tidb into ch…
Browse files Browse the repository at this point in the history
…erry-pick-expr-blacklist
  • Loading branch information
XuHuaiyu committed Jul 3, 2019
2 parents 3ff63e6 + 308488c commit 383544b
Show file tree
Hide file tree
Showing 22 changed files with 287 additions and 85 deletions.
29 changes: 29 additions & 0 deletions cmd/explaintest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,35 @@ HashAgg_18 24000.00 root group by:c1, funcs:firstrow(join_agg_0)
└─IndexReader_62 8000.00 root index:StreamAgg_53
└─StreamAgg_53 8000.00 cop group by:test.t2.c1, funcs:firstrow(test.t2.c1), firstrow(test.t2.c1)
└─IndexScan_60 10000.00 cop table:t2, index:c1, range:[NULL,+inf], keep order:true, stats:pseudo
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)
└─StreamAgg_28 1.00 root funcs:firstrow(col_0)
└─TableReader_29 1.00 root data:StreamAgg_17
└─StreamAgg_17 1.00 cop funcs:firstrow(1)
└─Selection_27 10.00 cop eq(test.t1.c3, 100)
└─TableScan_26 10000.00 cop 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
└─StreamAgg_17 1.00 root funcs:firstrow(col_0)
└─TableReader_18 1.00 root data:StreamAgg_9
└─StreamAgg_9 1.00 cop funcs:firstrow(1)
└─TableScan_16 10000.00 cop 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)
└─StreamAgg_23 1.00 root funcs:firstrow(col_0)
└─TableReader_24 1.00 root data:StreamAgg_15
└─StreamAgg_15 1.00 cop funcs:firstrow(1)
└─TableScan_22 10000.00 cop 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)
└─HashAgg_23 8000.00 root group by:col_1, funcs:firstrow(col_0)
└─TableReader_24 8000.00 root data:HashAgg_20
└─HashAgg_20 8000.00 cop group by:test.t1.c3, funcs:firstrow(1)
└─TableScan_15 10000.00 cop table:t1, range:[-inf,+inf], keep order:false, stats:pseudo
set @@session.tidb_opt_insubquery_unfold = 0;
explain select sum(t1.c1 in (select c1 from t2)) from t1;
id count task operator info
Expand Down
6 changes: 6 additions & 0 deletions cmd/explaintest/t/explain_easy.test
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ explain select if(10, t1.c1, t1.c2) from t1;
explain select c1 from t2 union select c1 from t2 union all select c1 from t2;
explain select c1 from t2 union all select c1 from t2 union select c1 from t2;

# https://github.com/pingcap/tidb/issues/9125
explain select count(1) from (select count(1) from (select * from t1 where c3 = 100) k) k2;
explain select 1 from (select count(c2), count(c3) from t1) k;
explain select count(1) from (select max(c2), count(c3) as m from t1) k;
explain select count(1) from (select count(c2) from t1 group by c3) k;

set @@session.tidb_opt_insubquery_unfold = 0;

explain select sum(t1.c1 in (select c1 from t2)) from t1;
Expand Down
9 changes: 9 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

. "github.com/pingcap/check"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/ast"
"github.com/pingcap/parser/charset"
"github.com/pingcap/parser/model"
Expand Down Expand Up @@ -2850,6 +2851,10 @@ func (s *testDBSuite) TestComment(c *C) {
}

func (s *testDBSuite) TestRebaseAutoID(c *C) {
c.Assert(failpoint.Enable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange", `return(true)`), IsNil)
defer func() {
c.Assert(failpoint.Disable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange"), IsNil)
}()
s.tk = testkit.NewTestKit(c, s.store)
s.tk.MustExec("use " + s.schemaName)

Expand Down Expand Up @@ -4657,6 +4662,10 @@ func (s *testDBSuite) TestCanceledJobTakeTime(c *C) {
}

func (s *testDBSuite) TestAlterShardRowIDBits(c *C) {
c.Assert(failpoint.Enable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange", `return(true)`), IsNil)
defer func() {
c.Assert(failpoint.Disable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange"), IsNil)
}()
s.tk = testkit.NewTestKit(c, s.store)
tk := s.tk

Expand Down
15 changes: 13 additions & 2 deletions domain/global_vars_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ type GlobalVariableCache struct {
lastModify time.Time
rows []chunk.Row
fields []*ast.ResultField

// Unit test may like to disable it.
disable bool
}

const globalVariableCacheExpiry time.Duration = 2 * time.Second
Expand All @@ -44,14 +47,22 @@ func (gvc *GlobalVariableCache) Update(rows []chunk.Row, fields []*ast.ResultFie
func (gvc *GlobalVariableCache) Get() (succ bool, rows []chunk.Row, fields []*ast.ResultField) {
gvc.RLock()
defer gvc.RUnlock()
if time.Now().Sub(gvc.lastModify) < globalVariableCacheExpiry {
succ, rows, fields = true, gvc.rows, gvc.fields
if time.Since(gvc.lastModify) < globalVariableCacheExpiry {
succ, rows, fields = !gvc.disable, gvc.rows, gvc.fields
return
}
succ = false
return
}

// Disable disables the global variabe cache, used in test only.
func (gvc *GlobalVariableCache) Disable() {
gvc.Lock()
defer gvc.Unlock()
gvc.disable = true
return
}

// GetGlobalVarsCache gets the global variable cache.
func (do *Domain) GetGlobalVarsCache() *GlobalVariableCache {
return &do.gvc
Expand Down
5 changes: 5 additions & 0 deletions executor/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"fmt"

. "github.com/pingcap/check"
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/model"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/meta/autoid"
Expand Down Expand Up @@ -536,6 +537,10 @@ func (s *testSuite) TestAdminCheckPrimaryIndex(c *C) {
}

func (s *testSuite) TestAdminShowNextID(c *C) {
c.Assert(failpoint.Enable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange", `return(true)`), IsNil)
defer func() {
c.Assert(failpoint.Disable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange"), IsNil)
}()
step := int64(10)
autoIDStep := autoid.GetStep()
autoid.SetStep(step)
Expand Down
2 changes: 2 additions & 0 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,8 @@ func (s *testSuite) TestOnlyFullGroupBy(c *C) {

// test AggregateFunc
tk.MustQuery("select max(a) from t group by d")
// for issue #8161: enable `any_value` in aggregation if `ONLY_FULL_GROUP_BY` is set
tk.MustQuery("select max(a), any_value(c) from t group by d;")
// test incompatible with sql_mode = ONLY_FULL_GROUP_BY
var err error
_, err = tk.Exec("select * from t group by d")
Expand Down
5 changes: 5 additions & 0 deletions executor/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

. "github.com/pingcap/check"
"github.com/pingcap/failpoint"
"github.com/pingcap/parser/model"
"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
Expand Down Expand Up @@ -260,6 +261,10 @@ func (s *testSuite) TestDefaultDBAfterDropCurDB(c *C) {
}

func (s *testSuite) TestRenameTable(c *C) {
c.Assert(failpoint.Enable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange", `return(true)`), IsNil)
defer func() {
c.Assert(failpoint.Disable("github.com/pingcap/tidb/meta/autoid/mockAutoIDChange"), IsNil)
}()
tk := testkit.NewTestKit(c, s.store)

tk.MustExec("create database rename1")
Expand Down
12 changes: 12 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3681,6 +3681,18 @@ func (s *testOOMSuite) TestDistSQLMemoryControl(c *C) {
tk.Se.GetSessionVars().MemQuotaDistSQL = -1
}

func (s *testSuite) TestOOMPanicAction(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t (a int primary key, b double);")
tk.MustExec("insert into t values (1,1)")
config.GetGlobalConfig().OOMAction = config.OOMActionCancel
tk.MustExec("set @@tidb_mem_quota_query=1;")
err := tk.QueryToErr("select sum(b) from t group by a;")
c.Assert(err, NotNil)
}

type oomCapturer struct {
zapcore.Core
tracker string
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ require (
github.com/pingcap/goleveldb v0.0.0-20171020084629-8d44bfdf1030
github.com/pingcap/kvproto v0.0.0-20190429124202-32a5ba2af0f7
github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596
github.com/pingcap/parser v0.0.0-20190620042621-a13211687e55
github.com/pingcap/parser v0.0.0-20190703021824-628683061f71
github.com/pingcap/pd v2.1.12+incompatible
github.com/pingcap/tidb-tools v2.1.3-0.20190116051332-34c808eef588+incompatible
github.com/pingcap/tipb v0.0.0-20180910045846-371b48b15d93
Expand Down Expand Up @@ -79,5 +79,3 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
)

replace github.com/pingcap/parser => github.com/XuHuaiyu/parser v0.0.0-20190701025952-1a27d824ea1d
Loading

0 comments on commit 383544b

Please sign in to comment.