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

Implement Select .... AS OF syntax to support Stale Read #24557

Closed
2 tasks done
nolouch opened this issue May 11, 2021 · 0 comments
Closed
2 tasks done

Implement Select .... AS OF syntax to support Stale Read #24557

nolouch opened this issue May 11, 2021 · 0 comments
Assignees
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@nolouch
Copy link
Member

nolouch commented May 11, 2021

Background

This is a subtask of #21094.
pingcap/parser#1206 has implemented the syntax of the Select .... FROM xxx AS OF timestamp xxx syntax, so we have to implement the syntax. for example, we can select with:

SELECT * FROM TABLE t AS OF TIMESTAMP '2020-02-02'

Implementation

SelectStmt is different with BeginStmt(#21897.). The read relative executors have a unified entry getSnapshotTS :

tidb/executor/builder.go

Lines 1358 to 1362 in 3eedd40

// `getSnapshotTS` returns the timestamp of the snapshot that a reader should read.
func (b *executorBuilder) getSnapshotTS() (uint64, error) {
// `refreshForUpdateTSForRC` should always be invoked before returning the cached value to
// ensure the correct value is returned even the `snapshotTS` field is already set by other
// logics. However for `IndexLookUpMergeJoin` and `IndexLookUpHashJoin`, it requires caching the

It gets TS from the session variable or the txn context build from the Optimize stage. we may need to change the behavior:

tidb/planner/optimize.go

Lines 116 to 124 in 3eedd40

if !useMaxTS(sctx, fp) {
sctx.PrepareTSFuture(ctx)
}
return fp, fp.OutputNames(), nil
}
}
sctx.PrepareTSFuture(ctx)

Tasks:

  • Make executor builder can set the specify ts with the as of Clause
  • Check multiple AS OF and make they are using the same TS. Our current framework is not very good to support one statement to specify multiple TS.
@nolouch nolouch added the type/enhancement The issue or PR belongs to an enhancement. label May 11, 2021
@nolouch nolouch self-assigned this May 11, 2021
@nolouch nolouch changed the title Implement Select .... AS OF syntax to Supports Stale Read Implement Select .... AS OF syntax to support Stale Read May 11, 2021
@nolouch nolouch closed this as completed Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

1 participant