diff --git a/expression/builtin_time.go b/expression/builtin_time.go index dcaac7b8556e7..4a38b44f1712b 100644 --- a/expression/builtin_time.go +++ b/expression/builtin_time.go @@ -7188,11 +7188,21 @@ func CalAppropriateTime(minTime, maxTime, minSafeTime time.Time) time.Time { // 2. If t2 < t, we will use t2 as the result, // and with it, a read request won't fail because it's bigger than the latest SafeTS. func calAppropriateTime(minTime, maxTime, minSafeTime time.Time) time.Time { - if minSafeTime.Before(minTime) { - return minTime - } else if minSafeTime.After(maxTime) { - return maxTime - } + if minSafeTime.Before(minTime) || minSafeTime.After(maxTime) { + logutil.BgLogger().Warn("calAppropriateTime", + zap.Time("minTime", minTime), + zap.Time("maxTime", maxTime), + zap.Time("minSafeTime", minSafeTime)) + if minSafeTime.Before(minTime) { + return minTime + } else if minSafeTime.After(maxTime) { + return maxTime + } + } + logutil.BgLogger().Debug("calAppropriateTime", + zap.Time("minTime", minTime), + zap.Time("maxTime", maxTime), + zap.Time("minSafeTime", minSafeTime)) return minSafeTime }