Stick to outdated stats rather than pseudo stats #27601
Closed
Description
Enhancement
A recent issue for reference, I was running tpc-c workload intensively. As the workload on-going and the auto analyze job failed due to "gc life time is shorter than transaction duration". the statistics did not got updated, then the statistics become outdated, the optimizer switch to pseudo stats and cause plan change.
This behavior assume that the pseudo stats is better than the outdated stats. This is not true.
I would suggest the optimizer sticked to the gathered stats, even it's outdated, to prevent plan change.
// getStatsTable gets statistics information for a table specified by "tableID".
// A pseudo statistics table is returned in any of the following scenario:
// 1. tidb-server started and statistics handle has not been initialized.
// 2. table row count from statistics is zero.
// 3. statistics is outdated.
func getStatsTable(ctx sessionctx.Context, tblInfo *model.TableInfo, pid int64) *statistics.Table {