planner: change the content of AnalyzeTableID to build global-stats#22554
planner: change the content of AnalyzeTableID to build global-stats#22554ti-srebot merged 22 commits intopingcap:masterfrom
Conversation
| if task.TableID.StoreAsCollectID() && len(task.TableID.CollectIDs) > 1 && !task.IndexInfo.Global && !task.IndexInfo.Unique { | ||
| b.buildAnalyzeFastIndex(e, task, v.Opts) | ||
| } else { | ||
| e.tasks = append(e.tasks, b.buildAnalyzeIndexPushdown(task, v.Opts, autoAnalyze)) | ||
| } |
There was a problem hiding this comment.
TODO: need more investigate here
There was a problem hiding this comment.
It seems OK since now we don't need fast analyze to collect partition statistics.
|
/run-all-tests |
rebelice
left a comment
There was a problem hiding this comment.
In the description, you say 'If the table is not the partition table, the PartitionID will be zero'. But in fact, it is -1 in the code.
Rest LGTM.
Sry, it's a typo in description. I have fixed it now. |
|
/run-all-tests |
|
TODO: need more investigation on the change of the execution plan. |
| "TableReader_5 4.00 root partition:all data:TableFullScan_4", | ||
| "└─TableFullScan_4 4.00 cop[tikv] table:t keep order:false" | ||
| "TableReader_5 10000.00 root partition:all data:TableFullScan_4", | ||
| "└─TableFullScan_4 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" |
|
/run-all-tests |
|
/run-all-tests |
| TblInfo: tbl.TableInfo, | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
Assume table t has three partitions p0, p1, p2. When executing analyze table t in StaticButPrepareDynamic mode, here we generate 6 IdxTasks while 3 may be enough since we save partition table stats for dynamic pruning now.
| testKit := testkit.NewTestKit(c, store) | ||
| testKit.MustExec("use test;") | ||
| testKit.MustExec("set @@tidb_partition_prune_mode = 'static-only';") | ||
| testKit.MustExec("set @@tidb_executor_concurrency = 1;") |
There was a problem hiding this comment.
The reason why we set @@tidb_executor_concurrency = 1 is due to the concurrent execution of PartitionUnion, we need the results to stabilize.
| if pruneMode == variable.StaticOnly || (pruneMode == variable.StaticButPrepareDynamic && !b.ctx.GetSessionVars().InRestrictedSQL) { | ||
| // static mode or static-but-prepare-dynamic mode not belong auto analyze need analyze each partition | ||
| // for static-but-prepare-dynamic mode with auto analyze, echo partition will be check before analyze partition. | ||
| for i, id := range physicalIDs { | ||
| info := analyzeInfo{DBName: tbl.Schema.O, TableName: tbl.Name.O, PartitionName: names[i], TableID: AnalyzeTableID{PersistID: id, CollectIDs: []int64{id}}, Incremental: as.Incremental} | ||
| p.IdxTasks = append(p.IdxTasks, AnalyzeIndexTask{ | ||
| IndexInfo: idx, | ||
| analyzeInfo: info, | ||
| TblInfo: tbl.TableInfo, | ||
| }) |
There was a problem hiding this comment.
We do not need to distinguish between different pruneMode here. Because no matter which mode it is, we need to build partition-level stats for each partitions. As for whether we need to build global-stats, we only need to check the pruneMode before building global-stats.
|
@xuyifangreeneyes, Thanks for your review. The bot only counts LGTMs from Reviewers and higher roles, but you're still welcome to leave your comments. See the corresponding SIG page for more information. Related SIGs: planner(slack),execution(slack). |
|
/run-all-tests |
|
/merge |
|
/run-all-tests |
What problem does this PR solve?
sub-PR for the PR#22472
Problem Summary:
We change the content for the
AnalyzeTableIDto build global-level stats. We useTableIDto represent the ID of the table. And use thePartitionIDto represent the ID of the partition. If the table is not the partition table, thePartitionIDwill be -1.What is changed and how it works?
As the above described.
Related changes
pingcap/docs/pingcap/docs-cn:Check List
Tests
Side effects
Release note