https://github.com/pingcap/tidb/blob/master/pkg/sessiontxn/isolation/readcommitted.go#L297
// AdviseOptimizeWithPlan in read-committed covers as many cases as repeatable-read.
// We do not fetch latest ts immediately for such scenes.
// 1. A query like the form of “SELECT … FOR UPDATE” whose execution plan is “PointGet”.
// 2. An INSERT statement without “SELECT” subquery.
// 3. A UPDATE statement whose sub execution plan is “PointGet”.
// 4. A DELETE statement whose sub execution plan is “PointGet”.
几乎全对。
你写的这段好像是在这个里面实现的。
看上去确实有几种场景不需要检查ts。
而且根据事务隔离级别的不一样,这个方法的实现也不一样。
如果需要检查ts,就把这个变量打开。
p.checkTSInWriteStmt = true
看了个大概,不甚准确。