Skip to content

Make AsOf compatible with Prepare #24932

Description

@nolouch

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.

Metadata

Metadata

Assignees

Labels

type/enhancementThe issue or PR belongs to an enhancement.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions