Skip to content

Commit

Permalink
add more test & improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
foreyes committed Aug 20, 2019
1 parent 2fdfc0b commit bebb8ee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 6 additions & 2 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const (
HintHashAgg = "hash_agg"
// HintStreamAgg is hint enforce stream aggregation.
HintStreamAgg = "stream_agg"
// HintIndex is hint enforce use some indexes.
// HintIndex is hint enforce using some indexes.
HintIndex = "index"
)

Expand Down Expand Up @@ -2277,7 +2277,11 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as
return nil, ErrPartitionClauseOnNonpartitioned
}

possiblePaths, err := b.getPossibleAccessPaths(tn.IndexHints, tableInfo, asName)
tblName := *asName
if tblName.L == "" {
tblName = tn.Name
}
possiblePaths, err := b.getPossibleAccessPaths(tn.IndexHints, tableInfo, tblName)
if err != nil {
return nil, err
}
Expand Down
12 changes: 5 additions & 7 deletions planner/core/physical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1724,22 +1724,20 @@ func (s *testPlanSuite) TestIndexHint(c *C) {
}{
// simple case
{
sql: "select /*+ INDEX(t, c_d_e) */ * from t t1",
sql: "select /*+ INDEX(t, c_d_e) */ * from t",
best: "IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))",
hasWarn: false,
},
{
sql: "select /*+ INDEX(t1, c_d_e) */ * from t t1",
best: "IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))",
sql: "select /*+ INDEX(t, c_d_e) */ * from t t1",
best: "TableReader(Table(t))",
hasWarn: false,
},
// test use original table name
{
sql: "select /*+ INDEX(t, c_d_e) */ * from t t1, t t2 where t1.a = t2.b",
best: "LeftHashJoin{IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))->IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))}(test.t1.a,test.t2.b)",
sql: "select /*+ INDEX(t1, c_d_e) */ * from t t1",
best: "IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))",
hasWarn: false,
},
// test use table alias
{
sql: "select /*+ INDEX(t1, c_d_e), INDEX(t2, f) */ * from t t1, t t2 where t1.a = t2.b",
best: "LeftHashJoin{IndexLookUp(Index(t.c_d_e)[[NULL,+inf]], Table(t))->IndexLookUp(Index(t.f)[[NULL,+inf]], Table(t))}(test.t1.a,test.t2.b)",
Expand Down
4 changes: 2 additions & 2 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func isPrimaryIndex(indexName model.CIStr) bool {
return indexName.L == "primary"
}

func (b *PlanBuilder) getPossibleAccessPaths(indexHints []*ast.IndexHint, tblInfo *model.TableInfo, asName *model.CIStr) ([]*accessPath, error) {
func (b *PlanBuilder) getPossibleAccessPaths(indexHints []*ast.IndexHint, tblInfo *model.TableInfo, tblName model.CIStr) ([]*accessPath, error) {
publicPaths := make([]*accessPath, 0, len(tblInfo.Indices)+1)
publicPaths = append(publicPaths, &accessPath{isTablePath: true})
for _, index := range tblInfo.Indices {
Expand All @@ -542,7 +542,7 @@ func (b *PlanBuilder) getPossibleAccessPaths(indexHints []*ast.IndexHint, tblInf
indexHintsLen := len(indexHints)
if hints := b.TableHints(); hints != nil {
for _, hint := range hints.indexHintList {
if hint.tblName == *asName {
if hint.tblName == tblName {
indexHints = append(indexHints, hint.indexHint)
}
}
Expand Down

0 comments on commit bebb8ee

Please sign in to comment.