Skip to content

Commit

Permalink
planner: choose TableScan when use an empty index hint (pingcap#12037)
Browse files Browse the repository at this point in the history
  • Loading branch information
francis0407 authored and foreyes committed Sep 16, 2019
1 parent 834b792 commit 57c8267
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1968,7 +1968,7 @@ func (b *PlanBuilder) pushTableHints(hints []*ast.TableOptimizerHint, nodeType n
case HintAggToCop:
aggHints.preferAggToCop = true
case HintIndex:
if len(hint.Tables) != 0 && len(hint.Indexes) != 0 {
if len(hint.Tables) != 0 {
indexHintList = append(indexHintList, indexHintInfo{
tblName: hint.Tables[0].TableName,
indexHint: &ast.IndexHint{
Expand Down
10 changes: 10 additions & 0 deletions planner/core/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,16 @@ func getTablePath(paths []*accessPath) *accessPath {
return nil
}

// getTablePath finds the TablePath from a group of accessPaths.
func getTablePath(paths []*accessPath) *accessPath {
for _, path := range paths {
if path.isTablePath {
return path
}
}
return nil
}

// deriveTablePathStats will fulfill the information that the accessPath need.
// And it will check whether the primary key is covered only by point query.
func (ds *DataSource) deriveTablePathStats(path *accessPath) (bool, error) {
Expand Down
6 changes: 6 additions & 0 deletions planner/core/physical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,12 @@ func (s *testPlanSuite) TestIndexHint(c *C) {
best: "IndexLookUp(Index(t.f)[[NULL,+inf]], Table(t))",
hasWarn: false,
},
// use TablePath when the hint only contains table.
{
sql: "select /*+ INDEX(t) */ f from t where f > 10",
best: "TableReader(Table(t)->Sel([gt(test.t.f, 10)]))",
hasWarn: false,
},
// there will be a warning instead of error when index not exist
{
sql: "select /*+ INDEX(t, no_such_index) */ * from t",
Expand Down

0 comments on commit 57c8267

Please sign in to comment.