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.
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
Planand also cache theschema version. we may use the As Of such as :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:
tidb/planner/core/common_plans.go
Lines 258 to 273 in e87d035
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.