-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
planner: check index valid while forUpdateRead #22152
Changes from 4 commits
63d2fe6
069340f
a1a2c47
13a4ba0
ace8009
945f4cf
f6cac2f
ac74dd7
19e9dfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2253,6 +2253,10 @@ func (r *correlatedAggregateResolver) resolveSelect(sel *ast.SelectStmt) (err er | |||||||||||||
if err != nil { | ||||||||||||||
return err | ||||||||||||||
} | ||||||||||||||
// do not use cache when for update read | ||||||||||||||
if isForUpdateReadSelectLock(sel.LockInfo) { | ||||||||||||||
useCache = false | ||||||||||||||
} | ||||||||||||||
// we cannot use cache if there are correlated aggregates inside FROM clause, | ||||||||||||||
// since the plan we are building now is not correct and need to be rebuild later. | ||||||||||||||
p, err := r.b.buildTableRefs(r.ctx, sel.From, useCache) | ||||||||||||||
|
@@ -3290,6 +3294,11 @@ func (b *PlanBuilder) buildSelect(ctx context.Context, sel *ast.SelectStmt) (p L | |||||||||||||
projExprs []expression.Expression | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
// set for update read to true before building result set node | ||||||||||||||
if isForUpdateReadSelectLock(sel.LockInfo) { | ||||||||||||||
b.isForUpdateRead = true | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// For sub-queries, the FROM clause may have already been built in outer query when resolving correlated aggregates. | ||||||||||||||
// If the ResultSetNode inside FROM clause has nothing to do with correlated aggregates, we can simply get the | ||||||||||||||
// existing ResultSetNode from the cache. | ||||||||||||||
|
@@ -3599,7 +3608,7 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as | |||||||||||||
if tblName.L == "" { | ||||||||||||||
tblName = tn.Name | ||||||||||||||
} | ||||||||||||||
possiblePaths, err := getPossibleAccessPaths(b.ctx, b.TableHints(), tn.IndexHints, tbl, dbName, tblName) | ||||||||||||||
possiblePaths, err := getPossibleAccessPaths(b.ctx, b.TableHints(), tn.IndexHints, tbl, dbName, tblName, b.isForUpdateRead, b.is.SchemaMetaVersion()) | ||||||||||||||
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.
for sql:
the value in this line should be:
but current get:
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. Good catch, added some cases for |
||||||||||||||
if err != nil { | ||||||||||||||
return nil, err | ||||||||||||||
} | ||||||||||||||
|
@@ -3696,6 +3705,8 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as | |||||||||||||
partitionNames: tn.PartitionNames, | ||||||||||||||
TblCols: make([]*expression.Column, 0, len(columns)), | ||||||||||||||
preferPartitions: make(map[int][]model.CIStr), | ||||||||||||||
is: b.is, | ||||||||||||||
isForUpdateRead: b.isForUpdateRead, | ||||||||||||||
}.Init(b.ctx, b.getSelectOffset()) | ||||||||||||||
var handleCols HandleCols | ||||||||||||||
schema := expression.NewSchema(make([]*expression.Column, 0, len(columns))...) | ||||||||||||||
|
@@ -4221,6 +4232,7 @@ func (b *PlanBuilder) buildUpdate(ctx context.Context, update *ast.UpdateStmt) ( | |||||||||||||
} | ||||||||||||||
|
||||||||||||||
b.inUpdateStmt = true | ||||||||||||||
b.isForUpdateRead = true | ||||||||||||||
|
||||||||||||||
p, err := b.buildResultSetNode(ctx, update.TableRefs.TableRefs) | ||||||||||||||
if err != nil { | ||||||||||||||
|
@@ -4561,6 +4573,7 @@ func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) ( | |||||||||||||
}() | ||||||||||||||
|
||||||||||||||
b.inDeleteStmt = true | ||||||||||||||
b.isForUpdateRead = true | ||||||||||||||
|
||||||||||||||
p, err := b.buildResultSetNode(ctx, delete.TableRefs.TableRefs) | ||||||||||||||
if err != nil { | ||||||||||||||
|
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.
after debug, it seems
useCache = false
only not-use-cache, but it still refill cache..so in Access Path Selection will happen in
correlatedAggregateResolver
and directly use cache in later buildProjectionThere 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.
Seems
useCache = false
only cache sub-sub-query when there is a select stmt inside from clause.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.
I added some cases for sub queries, the cache problem is also related with rewrite, it may be solved together with it.