-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plan: remove other accessPath
s if one is unique key and full matched.
#6925
Changes from 8 commits
d2b83a6
1aea370
a352724
5ae90d3
d5058ee
baa97cf
d098c09
4593783
929fc2e
c4770a0
b71b70f
b385a40
3dd9749
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,7 +334,9 @@ type accessPath struct { | |
forced bool | ||
} | ||
|
||
func (ds *DataSource) deriveTablePathStats(path *accessPath) error { | ||
// 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) { | ||
var err error | ||
sc := ds.ctx.GetSessionVars().StmtCtx | ||
path.countAfterAccess = float64(ds.statisticTable.Count) | ||
|
@@ -347,11 +349,11 @@ func (ds *DataSource) deriveTablePathStats(path *accessPath) error { | |
} | ||
if pkCol == nil { | ||
path.ranges = ranger.FullIntRange(false) | ||
return nil | ||
return false, nil | ||
} | ||
path.ranges = ranger.FullIntRange(mysql.HasUnsignedFlag(pkCol.RetType.Flag)) | ||
if len(ds.pushedDownConds) == 0 { | ||
return nil | ||
return false, nil | ||
} | ||
path.accessConds, path.tableFilters = ranger.DetachCondsForTableRange(ds.ctx, ds.pushedDownConds, pkCol) | ||
// If there's no access cond, we try to find that whether there's expression containing correlated column that | ||
|
@@ -387,17 +389,28 @@ func (ds *DataSource) deriveTablePathStats(path *accessPath) error { | |
} | ||
if corColInAccessConds { | ||
path.countAfterAccess = 1 | ||
return nil | ||
return true, nil | ||
} | ||
path.ranges, err = ranger.BuildTableRange(path.accessConds, sc, pkCol.RetType) | ||
if err != nil { | ||
return errors.Trace(err) | ||
return false, errors.Trace(err) | ||
} | ||
path.countAfterAccess, err = ds.statisticTable.GetRowCountByIntColumnRanges(sc, pkCol.ID, path.ranges) | ||
return errors.Trace(err) | ||
// Check whether the primary key is covered by point query. | ||
noIntervalRange := true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comments here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about s/noIntervalRange/allPointRanges/? This variable renaming can make code logic more clear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/noIntervalRange/allPointRanges/ or s/noIntervalRange/onlyPoint/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any example? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like a > 5 and a < 3... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
for _, ran := range path.ranges { | ||
if !ran.IsPoint(sc) { | ||
noIntervalRange = false | ||
break | ||
} | ||
} | ||
return noIntervalRange, errors.Trace(err) | ||
} | ||
|
||
func (ds *DataSource) deriveIndexPathStats(path *accessPath) error { | ||
// deriveIndexPathStats will fulfill the information that the accessPath need. | ||
// And it will check whether this index is full matched by point query. We will use this check to | ||
// determine whether we remove other paths or not. | ||
func (ds *DataSource) deriveIndexPathStats(path *accessPath) (bool, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
var err error | ||
sc := ds.ctx.GetSessionVars().StmtCtx | ||
path.ranges = ranger.FullRange() | ||
|
@@ -406,11 +419,11 @@ func (ds *DataSource) deriveIndexPathStats(path *accessPath) error { | |
if len(path.idxCols) != 0 { | ||
path.ranges, path.accessConds, path.tableFilters, path.eqCondCount, err = ranger.DetachCondAndBuildRangeForIndex(ds.ctx, ds.pushedDownConds, path.idxCols, path.idxColLens) | ||
if err != nil { | ||
return errors.Trace(err) | ||
return false, errors.Trace(err) | ||
} | ||
path.countAfterAccess, err = ds.statisticTable.GetRowCountByIndexRanges(sc, path.index.ID, path.ranges) | ||
if err != nil { | ||
return errors.Trace(err) | ||
return false, errors.Trace(err) | ||
} | ||
} else { | ||
path.tableFilters = ds.pushedDownConds | ||
|
@@ -441,7 +454,16 @@ func (ds *DataSource) deriveIndexPathStats(path *accessPath) error { | |
} | ||
path.countAfterIndex = math.Max(path.countAfterAccess*selectivity, ds.statsAfterSelect.count) | ||
} | ||
return nil | ||
// Check whether there's only point query. | ||
noIntervalRanges := true | ||
for _, ran := range path.ranges { | ||
// Not point or the not full matched. | ||
if !ran.IsPoint(sc) || len(ran.HighVal) != len(path.index.Columns) { | ||
noIntervalRanges = false | ||
break | ||
} | ||
} | ||
return noIntervalRanges, nil | ||
} | ||
|
||
func (path *accessPath) splitCorColAccessCondFromFilters() (access, remained []expression.Expression) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment for the newly added return value.