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

Make AsOf compatible with Prepare #24932

Closed
nolouch opened this issue May 27, 2021 · 2 comments · Fixed by #25156
Closed

Make AsOf compatible with Prepare #24932

nolouch opened this issue May 27, 2021 · 2 comments · Fixed by #25156
Assignees
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@nolouch
Copy link
Member

nolouch commented May 27, 2021

Background

AsOf mainly used in the stale read scenes. details in #21094. we need to let it compatible with Prepare.

As Prepare will cache the Plan and also cache the schema version. we may use the As Of such as :

"PREPARE mystmt SELECT * FROM table t AS OF TIMESTAMP NOW() - 2 SECOND where id=?";

If the schema is changed we should rebuild the prepare object in the cache.

Details Implement

Currently, the prepare process already has the check schema version step:

if prepared.SchemaVersion != is.SchemaMetaVersion() {
// In order to avoid some correctness issues, we have to clear the
// cached plan once the schema version is changed.
// Cached plan in prepared struct does NOT have a "cache key" with
// schema version like prepared plan cache key
prepared.CachedPlan = nil
preparedObj.Executor = nil
// If the schema version has changed we need to preprocess it again,
// if this time it failed, the real reason for the error is schema changed.
err := Preprocess(sctx, prepared.Stmt, is, InPrepare)
if err != nil {
return ErrSchemaChanged.GenWithStack("Schema change caused error: %s", err.Error())
}
prepared.SchemaVersion = is.SchemaMetaVersion()
}

We need to use the schema in the paste (define in the as of) to compare, do not use the latest schema. we may need to cache the as of Expr, then calculate the snapshots and the relative schema.

@nolouch
Copy link
Member Author

nolouch commented May 31, 2021

cc @xhebox @JmPotato
Can you help to solve this?

@xhebox
Copy link
Contributor

xhebox commented May 31, 2021

I am on it.

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

Successfully merging a pull request may close this issue.

2 participants