Skip to content

Commit

Permalink
Merge branch 'master' into zimuxia/charset
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala committed Sep 9, 2021
2 parents bf307f9 + ef0098a commit 9ac2433
Show file tree
Hide file tree
Showing 407 changed files with 20,973 additions and 9,436 deletions.
9 changes: 0 additions & 9 deletions .github/.licenserc.yaml → .github/licenserc.yml
Expand Up @@ -8,7 +8,6 @@ header:
- '.gitignore'
- '.gitattributes'
- '.golangci.yml'
- '.licenserc.yaml'
- 'LICENSES/'
- '**/*.md'
- '**/*.json'
Expand All @@ -29,13 +28,6 @@ header:
- '.github/'
# The license checker think the following 68 files do not have valid header licenses, need to be discussed.
# Ignore them for now.
- 'cmd/explaintest/config.toml'
- 'cmd/importer/config.toml'
- 'cmd/portgenerator/portgenerator.go'
- 'ddl/ddl.go'
- 'ddl/ddl_api.go'
- 'ddl/mock.go'
- 'ddl/options.go'
- 'executor/aggfuncs/func_stddevpop_test.go'
- 'executor/aggfuncs/func_stddevsamp_test.go'
- 'executor/aggfuncs/func_varpop_test.go'
Expand Down Expand Up @@ -71,7 +63,6 @@ header:
- 'session/bootstrap.go'
- 'session/session.go'
- 'session/tidb.go'
- 'store/driver/kv_test.go'
- 'store/mockstore/unistore/config/config-template.toml'
- 'store/mockstore/unistore/server/server.go'
- 'table/column.go'
Expand Down
63 changes: 0 additions & 63 deletions .github/workflows/assign_project.yml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/bug-closed.yml
@@ -0,0 +1,29 @@
name: Bug Closed

on:
issues:
types:
- closed

jobs:
label_issues:
if: |
contains(github.event.issue.labels.*.name, 'type/bug') &&
!(contains(join(github.event.issue.labels.*.name, ', '), 'affects-') &&
contains(join(github.event.issue.labels.*.name, ', '), 'backport-'))
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Label issues
uses: andymckay/labeler@1.0.3
with:
add-labels: "needs-more-info"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Add comment
uses: peter-evans/create-or-update-comment@v1.4.5
with:
issue-number: ${{ github.event.issue.number }}
body: |
Please check whether the issue should be labeled with 'affects-x.y' or 'backport-x.y.z',
and then remove 'needs-more-info' label.
20 changes: 0 additions & 20 deletions .github/workflows/issue_assigned.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/license-checker.yml
Expand Up @@ -20,4 +20,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
log: info
config: .github/.licenserc.yaml
config: .github/licenserc.yml
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -14,7 +14,7 @@

include Makefile.common

.PHONY: all clean test gotest server dev benchkv benchraw check checklist parser tidy ddltest
.PHONY: all clean test gotest server dev benchkv benchraw check checklist parser tidy ddltest build_br build_lightning build_lightning-ctl

default: server buildsucc

Expand Down
222 changes: 222 additions & 0 deletions bindinfo/bind_test.go
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"os"
"strconv"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -2452,3 +2453,224 @@ func (s *testSerialSuite) TestOptimizeOnlyOnce(c *C) {
tk.MustQuery("select * from t").Check(testkit.Rows())
c.Assert(failpoint.Disable("github.com/pingcap/tidb/planner/checkOptimizeCountOne"), IsNil)
}

func (s *testSerialSuite) TestIssue26377(c *C) {
tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
tk.MustExec("set tidb_enable_global_temporary_table = true")
tk.MustExec("set @@tidb_enable_noop_functions=1;")
tk.MustExec("drop table if exists t1,tmp1")
tk.MustExec("create table t1(a int(11))")
tk.MustExec("create global temporary table tmp1(a int(11), key idx_a(a)) on commit delete rows;")
tk.MustExec("create temporary table tmp2(a int(11), key idx_a(a));")

queries := []string{
"create global binding for with cte1 as (select a from tmp1) select * from cte1 using with cte1 as (select a from tmp1) select * from cte1",
"create global binding for select * from t1 inner join tmp1 on t1.a=tmp1.a using select * from t1 inner join tmp1 on t1.a=tmp1.a;",
"create global binding for select * from t1 where t1.a in (select a from tmp1) using select * from t1 where t1.a in (select a from tmp1 use index (idx_a));",
"create global binding for select a from t1 union select a from tmp1 using select a from t1 union select a from tmp1 use index (idx_a);",
"create global binding for select t1.a, (select a from tmp1 where tmp1.a=1) as t2 from t1 using select t1.a, (select a from tmp1 where tmp1.a=1) as t2 from t1;",
"create global binding for select * from (select * from tmp1) using select * from (select * from tmp1);",
"create global binding for select * from t1 where t1.a = (select a from tmp1) using select * from t1 where t1.a = (select a from tmp1)",
}
genLocalTemporarySQL := func(sql string) string {
return strings.Replace(sql, "tmp1", "tmp2", -1)
}
for _, query := range queries {
localSQL := genLocalTemporarySQL(query)
queries = append(queries, localSQL)
}

for _, q := range queries {
tk.MustGetErrCode(q, errno.ErrOptOnTemporaryTable)
}
}

func (s *testSerialSuite) TestIssue27422(c *C) {
tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
tk.MustExec("use test")
tk.MustExec("set tidb_enable_global_temporary_table = true")
tk.MustExec("set @@tidb_enable_noop_functions=1;")
tk.MustExec("drop table if exists t1,tmp1,tmp2")
tk.MustExec("create table t1(a int(11))")
tk.MustExec("create global temporary table tmp1(a int(11), key idx_a(a)) on commit delete rows;")
tk.MustExec("create temporary table tmp2(a int(11), key idx_a(a));")

queries := []string{
"create global binding for insert into t1 (select * from tmp1) using insert into t1 (select * from tmp1);",
"create global binding for update t1 inner join tmp1 on t1.a=tmp1.a set t1.a=1 using update t1 inner join tmp1 on t1.a=tmp1.a set t1.a=1",
"create global binding for update t1 set t1.a=(select a from tmp1) using update t1 set t1.a=(select a from tmp1)",
"create global binding for update t1 set t1.a=1 where t1.a = (select a from tmp1) using update t1 set t1.a=1 where t1.a = (select a from tmp1)",
"create global binding for with cte1 as (select a from tmp1) update t1 set t1.a=1 where t1.a in (select a from cte1) using with cte1 as (select a from tmp1) update t1 set t1.a=1 where t1.a in (select a from cte1)",
"create global binding for delete from t1 where t1.a in (select a from tmp1) using delete from t1 where t1.a in (select a from tmp1)",
"create global binding for delete from t1 where t1.a = (select a from tmp1) using delete from t1 where t1.a = (select a from tmp1)",
"create global binding for delete t1 from t1,tmp1 using delete t1 from t1,tmp1",
}
genLocalTemporarySQL := func(sql string) string {
return strings.Replace(sql, "tmp1", "tmp2", -1)
}
for _, query := range queries {
localSQL := genLocalTemporarySQL(query)
queries = append(queries, localSQL)
}

for _, q := range queries {
tk.MustGetErrCode(q, errno.ErrOptOnTemporaryTable)
}
}

func (s *testSuite) TestCaptureFilter(c *C) {
tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
stmtsummary.StmtSummaryByDigestMap.Clear()
tk.MustExec(" set @@tidb_capture_plan_baselines = on")
defer func() {
tk.MustExec(" set @@tidb_capture_plan_baselines = off")
}()
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a int)")

c.Assert(tk.Se.Auth(&auth.UserIdentity{Username: "root", Hostname: "%"}, nil, nil), IsTrue)
tk.MustExec("select * from t where a > 10")
tk.MustExec("select * from t where a > 10")
tk.MustExec("admin capture bindings")
rows := tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "select * from `test` . `t` where `a` > ?")

// Valid table filter.
s.cleanBindingEnv(tk)
stmtsummary.StmtSummaryByDigestMap.Clear()
tk.MustExec("insert into mysql.capture_plan_baselines_blacklist(filter_type, filter_value) values('table', 'test.t')")
tk.MustExec("select * from t where a > 10")
tk.MustExec("select * from t where a > 10")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 0)
tk.MustExec("select * from mysql.capture_plan_baselines_blacklist")
tk.MustExec("select * from mysql.capture_plan_baselines_blacklist")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "select * from `mysql` . `capture_plan_baselines_blacklist`")

tk.MustExec("delete from mysql.capture_plan_baselines_blacklist")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Sort().Rows()
c.Assert(len(rows), Equals, 2)
c.Assert(rows[0][0], Equals, "select * from `mysql` . `capture_plan_baselines_blacklist`")
c.Assert(rows[1][0], Equals, "select * from `test` . `t` where `a` > ?")

// Invalid table filter.
s.cleanBindingEnv(tk)
stmtsummary.StmtSummaryByDigestMap.Clear()
tk.MustExec("insert into mysql.capture_plan_baselines_blacklist(filter_type, filter_value) values('table', 't')")
tk.MustExec("select * from t where a > 10")
tk.MustExec("select * from t where a > 10")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "select * from `test` . `t` where `a` > ?")

// Valid database filter.
s.cleanBindingEnv(tk)
stmtsummary.StmtSummaryByDigestMap.Clear()
tk.MustExec("insert into mysql.capture_plan_baselines_blacklist(filter_type, filter_value) values('db', 'mysql')")
tk.MustExec("select * from mysql.capture_plan_baselines_blacklist")
tk.MustExec("select * from mysql.capture_plan_baselines_blacklist")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 0)
tk.MustExec("select * from t where a > 10")
tk.MustExec("select * from t where a > 10")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "select * from `test` . `t` where `a` > ?")

tk.MustExec("delete from mysql.capture_plan_baselines_blacklist")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Sort().Rows()
c.Assert(len(rows), Equals, 2)
c.Assert(rows[0][0], Equals, "select * from `mysql` . `capture_plan_baselines_blacklist`")
c.Assert(rows[1][0], Equals, "select * from `test` . `t` where `a` > ?")

// Valid frequency filter.
s.cleanBindingEnv(tk)
stmtsummary.StmtSummaryByDigestMap.Clear()
tk.MustExec("insert into mysql.capture_plan_baselines_blacklist(filter_type, filter_value) values('frequency', '2')")
tk.MustExec("select * from t where a > 10")
tk.MustExec("select * from t where a > 10")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 0)

tk.MustExec("select * from t where a > 10")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "select * from `test` . `t` where `a` > ?")
tk.MustExec("delete from mysql.capture_plan_baselines_blacklist")

// Invalid frequency filter.
s.cleanBindingEnv(tk)
stmtsummary.StmtSummaryByDigestMap.Clear()
tk.MustExec("insert into mysql.capture_plan_baselines_blacklist(filter_type, filter_value) values('frequency', '0')")
tk.MustExec("select * from t where a > 10")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 0)

tk.MustExec("select * from t where a > 10")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "select * from `test` . `t` where `a` > ?")
tk.MustExec("delete from mysql.capture_plan_baselines_blacklist")

// Invalid filter type.
s.cleanBindingEnv(tk)
stmtsummary.StmtSummaryByDigestMap.Clear()
tk.MustExec("insert into mysql.capture_plan_baselines_blacklist(filter_type, filter_value) values('unknown', 'xx')")
tk.MustExec("select * from t where a > 10")
tk.MustExec("select * from t where a > 10")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "select * from `test` . `t` where `a` > ?")
tk.MustExec("delete from mysql.capture_plan_baselines_blacklist")

// Case sensitivity.
s.cleanBindingEnv(tk)
stmtsummary.StmtSummaryByDigestMap.Clear()
tk.MustExec("insert into mysql.capture_plan_baselines_blacklist(filter_type, filter_value) values('tABle', 'tESt.T')")
tk.MustExec("select * from t where a > 10")
tk.MustExec("select * from t where a > 10")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 0)

tk.MustExec("delete from mysql.capture_plan_baselines_blacklist")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Sort().Rows()
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "select * from `test` . `t` where `a` > ?")

s.cleanBindingEnv(tk)
stmtsummary.StmtSummaryByDigestMap.Clear()
tk.MustExec("insert into mysql.capture_plan_baselines_blacklist(filter_type, filter_value) values('Db', 'mySQl')")
tk.MustExec("select * from mysql.capture_plan_baselines_blacklist")
tk.MustExec("select * from mysql.capture_plan_baselines_blacklist")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 0)

tk.MustExec("delete from mysql.capture_plan_baselines_blacklist")
tk.MustExec("admin capture bindings")
rows = tk.MustQuery("show global bindings").Sort().Rows()
c.Assert(len(rows), Equals, 1)
c.Assert(rows[0][0], Equals, "select * from `mysql` . `capture_plan_baselines_blacklist`")
}

0 comments on commit 9ac2433

Please sign in to comment.