Skip to content
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

executor: Support read operation for local temporary table #26353

Merged
merged 13 commits into from
Jul 20, 2021

Conversation

lcwangchao
Copy link
Collaborator

@lcwangchao lcwangchao commented Jul 19, 2021

What problem does this PR solve?

Issue Number: close #25920

Problem Summary:

Support read operation for local temporary table. PointGet/BatchPointGet are already supported in previous pr #26053 and #2629. So this pr finished last read operation for table scan.

What is changed and how it works?

For local temporary table, we force to use UnionScanExec to scan table for all data are in memory. We also introduced UnionIter to merge two MemBuff iters from session and transaction into one.

Because UnionScanExec does not support index merge, so it is forbidden on local temporary table.

Check List

Tests

  • Unit test

Side effects

  • N/A

Documentation

  • N/A

Release note

  • No release note

@ti-chi-bot ti-chi-bot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 19, 2021
@github-actions github-actions bot added sig/execution SIG execution sig/sql-infra SIG: SQL Infra labels Jul 19, 2021
)

// UnionIter implements kv.Iterator
type UnionIter struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnionIter is moved to the client-go repo and is now internal
https://github.com/tikv/client-go/blob/master/internal/unionstore/union_iter.go

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jul 20, 2021
Copy link
Contributor

@djshow832 djshow832 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM

@@ -4085,7 +4085,7 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as

var result LogicalPlan = ds
dirty := tableHasDirtyContent(b.ctx, tableInfo)
if dirty {
if dirty || tableInfo.TempTableType == model.TempTableLocal {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to update some comments. Such as LogicalUnionScan: "LogicalUnionScan is only used in non read-only txn.".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -327,7 +328,7 @@ func (ds *DataSource) DeriveStats(childStats []*property.StatsInfo, selfSchema *
}
}
}
if isPossibleIdxMerge && sessionAndStmtPermission && needConsiderIndexMerge && isReadOnlyTxn {
if isPossibleIdxMerge && sessionAndStmtPermission && needConsiderIndexMerge && isReadOnlyTxn && ds.tableInfo.TempTableType != model.TempTableLocal {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why skip index merge?

Copy link
Collaborator Author

@lcwangchao lcwangchao Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnionScan for index merge is just a TODO, so we must skip is because local temporary table always use UnionScan.

tidb/planner/core/stats.go

Lines 308 to 320 in cca097d

// TODO: implement UnionScan + IndexMerge
isReadOnlyTxn := true
txn, err := ds.ctx.Txn(false)
if err != nil {
return nil, err
}
if txn.Valid() && !txn.IsReadOnly() {
isReadOnlyTxn = false
}
// Consider the IndexMergePath. Now, we just generate `IndexMergePath` in DNF case.
isPossibleIdxMerge := len(ds.pushedDownConds) > 0 && len(ds.possibleAccessPaths) > 1
sessionAndStmtPermission := (ds.ctx.GetSessionVars().GetEnableIndexMerge() || len(ds.indexMergeHints) > 0) && !ds.ctx.GetSessionVars().StmtCtx.NoIndexMergeHint
// If there is an index path, we current do not consider `IndexMergePath`.

@ti-chi-bot
Copy link
Member

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • djshow832
  • tiancaiamao

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jul 20, 2021
@djshow832
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: e569e42

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 20, 2021
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Jul 20, 2021
@lcwangchao
Copy link
Collaborator Author

/run-check_dev_2

@lcwangchao lcwangchao added the status/can-merge Indicates a PR has been approved by a committer. label Jul 20, 2021
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Jul 20, 2021
@djshow832
Copy link
Contributor

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 1954958

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jul 20, 2021
@ti-chi-bot ti-chi-bot merged commit add2df6 into pingcap:master Jul 20, 2021
@lcwangchao lcwangchao deleted the temp_table_scan_reader branch July 20, 2021 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution sig/sql-infra SIG: SQL Infra size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support read operation to a local temporary table
4 participants