After tidb-server restarts, stats fail to load successfully

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb-server重启后stats一直没有加载成功

| username: dba-kit

After restarting the tidb-server, the stats have not been successfully loaded, and there was a panic error during this period. The final result is that all SQL on the restarted tidb-server followed the pseudo logic, causing many normal queries to use the wrong index, and the load on all TiKV nodes was very high. The error content is as follows:

[ERROR] [misc.go:116] ["panic in the recoverable goroutine"] [label=domain] [funcInfo=loadStatsWorker] [r="invalid memory address or nil pointer dereference"] [stack=github.com/pingcap/tidb/util.Recover
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/misc.go:120
runtime.gopanic
	/usr/local/go/src/runtime/panic.go:884
github.com/pingcap/tidb/executor.(*ExecStmt).Exec.func1
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:440
runtime.gopanic
	/usr/local/go/src/runtime/panic.go:884
runtime.panicmem
	/usr/local/go/src/runtime/panic.go:260
runtime.sigpanic
	/usr/local/go/src/runtime/signal_unix.go:835
github.com/pingcap/tidb/session.(*LazyTxn).SetOption
	<autogenerated>:1
github.com/pingcap/tidb/sessiontxn/isolation.(*PessimisticRCTxnContextProvider).getStmtTS
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/sessiontxn/isolation/readcommitted.go:193
github.com/pingcap/tidb/sessiontxn/isolation.(*baseTxnContextProvider).GetStmtReadTS
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/sessiontxn/isolation/base.go:189
github.com/pingcap/tidb/session.(*txnManager).GetStmtReadTS
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/txnmanager.go:84
github.com/pingcap/tidb/executor.(*executorBuilder).getSnapshotTS
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:1736
github.com/pingcap/tidb/executor.buildNoRangeIndexLookUpReader
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:3780
github.com/pingcap/tidb/executor.(*executorBuilder).buildIndexLookUpReader
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:3851
github.com/pingcap/tidb/executor.(*executorBuilder).build
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:287
github.com/pingcap/tidb/executor.(*executorBuilder).buildProjection
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:1685
github.com/pingcap/tidb/executor.(*executorBuilder).build
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:269
github.com/pingcap/tidb/executor.(*executorBuilder).buildStreamAgg
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:1641
github.com/pingcap/tidb/executor.(*executorBuilder).build
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/builder.go:267
github.com/pingcap/tidb/executor.(*ExecStmt).buildExecutor
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:1098
github.com/pingcap/tidb/executor.(*ExecStmt).Exec
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:500
github.com/pingcap/tidb/session.runStmt
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/session.go:2351
github.com/pingcap/tidb/session.(*session).ExecuteStmt
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/session.go:2215
github.com/pingcap/tidb/session.(*session).ExecuteInternal
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/session/session.go:1676
github.com/pingcap/tidb/statistics/handle.(*Handle).initTopNCountSum
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/statistics/handle/bootstrap.go:338
github.com/pingcap/tidb/statistics/handle.(*Handle).initStatsHistograms4Chunk
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/statistics/handle/bootstrap.go:144
github.com/pingcap/tidb/statistics/handle.(*Handle).initStatsHistograms
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/statistics/handle/bootstrap.go:185
github.com/pingcap/tidb/statistics/handle.(*Handle).InitStats
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/statistics/handle/bootstrap.go:415
github.com/pingcap/tidb/domain.(*Domain).loadStatsWorker
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/domain/domain.go:1882
github.com/pingcap/tidb/util.(*WaitGroupWrapper).Run.func1
	/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/wait_group_wrapper.go:33
| username: db_user | Original post link

It should be an existing bug, you can take a look at this,
The updateStatsWorker goroutine panic with invalid memory addr or nil pointer ref · Issue #35421 · pingcap/tidb (github.com)

| username: dba-kit | Original post link

[funcInfo=loadStatsWorker] [r=“"time: missing Location in call to Date"”]

The error in the issue is this, caused by a timezone problem. It should be different from my issue.