Skip to content

Commit

Permalink
Merge branch 'master' into release-4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala committed Mar 23, 2020
2 parents 0557713 + 7a09249 commit 1ec8511
Show file tree
Hide file tree
Showing 187 changed files with 10,015 additions and 7,645 deletions.
17 changes: 6 additions & 11 deletions .github/ISSUE_TEMPLATE/bug-report.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
---
name: "\U0001F41B Bug Report"
about: Something isn't working as expected
about: As a User, I want to report a Bug.
labels: type/bug
---

## Bug Report

Please answer these questions before submitting your issue. Thanks!

1. What did you do?
<!--If possible, provide a recipe for reproducing the error.-->
### 1. What did you do?

<!-- If possible, provide a recipe for reproducing the error. -->

2. What did you expect to see?
### 2. What did you expect to see?

### 3. What did you see instead?


3. What did you see instead?



4. What version of TiDB are you using (`tidb-server -V` or run `select tidb_version();` on TiDB)?

### 4. What version of TiDB are you using? (`tidb-server -V` or run `select tidb_version();` on TiDB)
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/challenge-program.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: "\U0001F947 Challenge Program"
about: Challenge Program issues
name: "\U0001F947 Propose a Challenge Program task"
about: As a developer, I want to propose a Challenge Program task.
labels: challenge-program-2
---

Expand Down
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/development-task.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: "\U0001F680 Development Task"
about: As a TiDB developer, I want to record a development task.
labels: type/enhancement
---

## Development Task
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/feature-request.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: "\U0001F680 Feature Request"
about: I have a suggestion
labels: type/enhancement
about: As a user, I want to request a New Feature on the product.
labels: type/feature-request
---

## Feature Request
Expand All @@ -16,4 +16,4 @@ labels: type/enhancement
<!-- A clear and concise description of any alternative solutions or features you've considered. -->

**Teachability, Documentation, Adoption, Migration Strategy:**
<!-- If you can, explain some scenarios how users might use this, situations it would be helpful in. Any API designs, mockups, or diagrams are also helpful. -->
<!-- If you can, explain some scenarios how users might use this, situations it would be helpful in. Any API designs, mockups, or diagrams are also helpful. -->
9 changes: 6 additions & 3 deletions .github/ISSUE_TEMPLATE/general-question.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
---
name: "\U0001F914 General Question"
about: Usage question that isn't answered in docs or discussion
labels: question
name: "\U0001F914 Ask a Question"
about: I want to ask a question.
labels: type/question
---

## General Question

<!--
Before asking a question, make sure you have:
- Searched existing Stack Overflow questions.
Expand All @@ -15,3 +17,4 @@ Before asking a question, make sure you have:
- [TiDB Readme](https://github.com/pingcap/tidb)
- [TiDB Doc](https://github.com/pingcap/docs)
-->
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/performance-questions.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: "\U0001F947 Performance Questions"
about: Performance question about TiDB which is not caused by bug.
labels: question, type/performance
name: "\U0001F947 Ask a Database Performance Question"
about: I want to ask a database performance question.
labels: type/question, type/performance
---

## Performance Questions
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/assign_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,32 @@ jobs:
with:
project: 'https://github.com/pingcap/tidb/projects/39'
column_name: 'Issue Backlog: Need Triage'
- name: Run issues assignment to Question and Bug Reports Kanban
uses: srggrs/assign-one-project-github-action@1.2.0
if: |
contains(github.event.issue.labels.*.name, 'type/question') ||
contains(github.event.issue.labels.*.name, 'type/bug')
with:
project: 'https://github.com/pingcap/tidb/projects/36'
column_name: 'Need Triage'
- name: Run issues assignment to Feature Request Kanban
uses: srggrs/assign-one-project-github-action@1.2.0
if: |
contains(github.event.issue.labels.*.name, 'type/feature-request')
with:
project: 'https://github.com/pingcap/tidb/projects/41'
column_name: 'Need Triage'
- name: Run issues assignment to Robust test
uses: srggrs/assign-one-project-github-action@1.2.0
if: |
contains(github.event.issue.labels.*.name, 'component/test')
with:
project: 'https://github.com/pingcap/tidb/projects/32'
column_name: 'TODO/Help Wanted'
- name: Run issues assignment to project UT Coverage
uses: srggrs/assign-one-project-github-action@1.2.0
if: |
contains(github.event.issue.labels.*.name, 'type/UT-coverage')
with:
project: 'https://github.com/pingcap/tidb/projects/44'
column_name: 'To do'
14 changes: 13 additions & 1 deletion bindinfo/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

package bindinfo

import "github.com/pingcap/parser/ast"
import (
"github.com/pingcap/parser"
"github.com/pingcap/parser/ast"
)

// HintsSet contains all hints of a query.
type HintsSet struct {
Expand Down Expand Up @@ -82,3 +85,12 @@ func BindHint(stmt ast.StmtNode, hintsSet *HintsSet) ast.StmtNode {
stmt.Accept(&hp)
return stmt
}

// ParseHintsSet parses a SQL string and collect HintsSet.
func ParseHintsSet(p *parser.Parser, sql, charset, collation string) (*HintsSet, error) {
stmtNode, err := p.ParseOneStmt(sql, charset, collation)
if err != nil {
return nil, err
}
return CollectHint(stmtNode), nil
}
35 changes: 29 additions & 6 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (s *testSuite) TestGlobalAndSessionBindingBothExist(c *C) {
tk.MustExec("drop table if exists t2")
tk.MustExec("create table t1(id int)")
tk.MustExec("create table t2(id int)")
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashLeftJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin"), IsTrue)

tk.MustExec("create global binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id")
Expand All @@ -345,11 +345,11 @@ func (s *testSuite) TestGlobalAndSessionBindingBothExist(c *C) {
metrics.BindUsageCounter.WithLabelValues(metrics.ScopeGlobal).Write(pb)
c.Assert(pb.GetCounter().GetValue(), Equals, float64(1))
tk.MustExec("set @@tidb_use_plan_baselines = 0")
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashLeftJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin"), IsTrue)

tk.MustExec("drop global binding for SELECT * from t1,t2 where t1.id = t2.id")
tk.MustExec("set @@tidb_use_plan_baselines = 1")
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashLeftJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin"), IsTrue)
}

func (s *testSuite) TestExplain(c *C) {
Expand All @@ -361,7 +361,7 @@ func (s *testSuite) TestExplain(c *C) {
tk.MustExec("create table t1(id int)")
tk.MustExec("create table t2(id int)")

c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashLeftJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT * from t1,t2 where t1.id = t2.id", "HashJoin"), IsTrue)
c.Assert(tk.HasPlan("SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id", "MergeJoin"), IsTrue)

tk.MustExec("create global binding for SELECT * from t1,t2 where t1.id = t2.id using SELECT /*+ TIDB_SMJ(t1, t2) */ * from t1,t2 where t1.id = t2.id")
Expand All @@ -383,14 +383,14 @@ func (s *testSuite) TestBindingSymbolList(c *C) {
// before binding
tk.MustQuery("select a, b from t where a = 3 limit 1, 100")
c.Assert(tk.Se.GetSessionVars().StmtCtx.IndexNames[0], Equals, "t:ia")
c.Assert(tk.MustUseIndex("select a, b from t where a = 3 limit 1, 100", "a"), IsTrue)
c.Assert(tk.MustUseIndex("select a, b from t where a = 3 limit 1, 100", "ia(a)"), IsTrue)

tk.MustExec(`create global binding for select a, b from t where a = 1 limit 0, 1 using select a, b from t use index (ib) where a = 1 limit 0, 1`)

// after binding
tk.MustQuery("select a, b from t where a = 3 limit 1, 100")
c.Assert(tk.Se.GetSessionVars().StmtCtx.IndexNames[0], Equals, "t:ib")
c.Assert(tk.MustUseIndex("select a, b from t where a = 3 limit 1, 100", "b"), IsTrue)
c.Assert(tk.MustUseIndex("select a, b from t where a = 3 limit 1, 100", "ib(b)"), IsTrue)

// Normalize
sql, hash := parser.NormalizeDigest("select a, b from t where a = 1 limit 0, 1")
Expand Down Expand Up @@ -707,3 +707,26 @@ func (s *testSuite) TestPrivileges(c *C) {
rows = tk.MustQuery("show global bindings").Rows()
c.Assert(len(rows), Equals, 0)
}

func (s *testSuite) TestHintsSetEvolveTask(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, index idx_a(a))")
tk.MustExec("create global binding for select * from t where a > 10 using select * from t ignore index(idx_a) where a > 10")
tk.MustExec("set @@tidb_evolve_plan_baselines=1")
tk.MustQuery("select * from t use index(idx_a) where a > 0")
bindHandle := s.domain.BindHandle()
bindHandle.SaveEvolveTasksToStore()
// Verify the added Binding for evolution contains valid ID and Hint, otherwise, panic may happen.
sql, hash := parser.NormalizeDigest("select * from t where a > ?")
bindData := bindHandle.GetBindRecord(hash, sql, "test")
c.Check(bindData, NotNil)
c.Check(bindData.OriginalSQL, Equals, "select * from t where a > ?")
c.Assert(len(bindData.Bindings), Equals, 2)
bind := bindData.Bindings[1]
c.Assert(bind.Status, Equals, bindinfo.PendingVerify)
c.Assert(bind.ID, Not(Equals), "")
c.Assert(bind.Hint, NotNil)
}
20 changes: 10 additions & 10 deletions bindinfo/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ type Binding struct {
Collation string
// Hint is the parsed hints, it is used to bind hints to stmt node.
Hint *HintsSet
// id is the string form of all hints. It is used to uniquely identify different hints.
// ID is the string form of all hints. It is used to uniquely identify different hints.
// It would be non-empty only when the status is `Using` or `PendingVerify`.
id string
ID string
}

func (b *Binding) isSame(rb *Binding) bool {
if b.id != "" && rb.id != "" {
return b.id == rb.id
if b.ID != "" && rb.ID != "" {
return b.ID == rb.ID
}
// Sometimes we cannot construct `id` because of the changed schema, so we need to compare by bind sql.
// Sometimes we cannot construct `ID` because of the changed schema, so we need to compare by bind sql.
return b.BindSQL == rb.BindSQL
}

Expand Down Expand Up @@ -96,7 +96,7 @@ func (br *BindRecord) HasUsingBinding() bool {
// FindBinding find bindings in BindRecord.
func (br *BindRecord) FindBinding(hint string) *Binding {
for _, binding := range br.Bindings {
if binding.id == hint {
if binding.ID == hint {
return &binding
}
}
Expand All @@ -106,19 +106,19 @@ func (br *BindRecord) FindBinding(hint string) *Binding {
func (br *BindRecord) prepareHints(sctx sessionctx.Context) error {
p := parser.New()
for i, bind := range br.Bindings {
if bind.Hint != nil || bind.id != "" || bind.Status == deleted {
if (bind.Hint != nil && bind.ID != "") || bind.Status == deleted {
continue
}
stmtNode, err := p.ParseOneStmt(bind.BindSQL, bind.Charset, bind.Collation)
hintsSet, err := ParseHintsSet(p, bind.BindSQL, bind.Charset, bind.Collation)
if err != nil {
return err
}
hints, err := getHintsForSQL(sctx, bind.BindSQL)
if err != nil {
return err
}
br.Bindings[i].Hint = CollectHint(stmtNode)
br.Bindings[i].id = hints
br.Bindings[i].Hint = hintsSet
br.Bindings[i].ID = hints
}
return nil
}
Expand Down
Loading

0 comments on commit 1ec8511

Please sign in to comment.