Skip to content

planner: change the content of AnalyzeTableID to build global-stats#22554

Merged
ti-srebot merged 22 commits intopingcap:masterfrom
Reminiscent:buildGlobalStats-0
Feb 2, 2021
Merged

planner: change the content of AnalyzeTableID to build global-stats#22554
ti-srebot merged 22 commits intopingcap:masterfrom
Reminiscent:buildGlobalStats-0

Conversation

@Reminiscent
Copy link
Contributor

@Reminiscent Reminiscent commented Jan 27, 2021

What problem does this PR solve?

sub-PR for the PR#22472

Problem Summary:
We change the content for the AnalyzeTableID to build global-level stats. We use TableID to represent the ID of the table. And use the PartitionID to represent the ID of the partition. If the table is not the partition table, the PartitionID will be -1.

What is changed and how it works?

As the above described.

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test

Side effects

  • We can not use the global-stats in 'dynamic-only' mode until the PR#22472 merged.

Release note

  • No release note

@Reminiscent Reminiscent requested review from a team as code owners January 27, 2021 03:40
@Reminiscent Reminiscent requested review from lzmhhh123 and removed request for a team January 27, 2021 03:40
@github-actions github-actions bot added the sig/execution SIG execution label Jan 27, 2021
Comment on lines -2188 to -2192
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))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: need more investigate here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems OK since now we don't need fast analyze to collect partition statistics.

@Reminiscent
Copy link
Contributor Author

/run-all-tests

Copy link
Contributor

@rebelice rebelice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Reminiscent
Copy link
Contributor Author

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.

@Reminiscent
Copy link
Contributor Author

/run-all-tests

@Reminiscent
Copy link
Contributor Author

TODO: need more investigation on the change of the execution plan.

Comment on lines +395 to +396
"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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use pseudo here?

@Reminiscent
Copy link
Contributor Author

/run-all-tests

@github-actions github-actions bot added the sig/planner SIG: Planner label Jan 29, 2021
@Reminiscent
Copy link
Contributor Author

/run-all-tests

TblInfo: tbl.TableInfo,
})
}
}
Copy link
Contributor

@xuyifangreeneyes xuyifangreeneyes Jan 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;")
Copy link
Contributor Author

@Reminiscent Reminiscent Feb 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why we set @@tidb_executor_concurrency = 1 is due to the concurrent execution of PartitionUnion, we need the results to stabilize.

Comment on lines -1698 to -1707
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,
})
Copy link
Contributor Author

@Reminiscent Reminiscent Feb 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@xuyifangreeneyes xuyifangreeneyes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-srebot
Copy link
Contributor

@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).

@Reminiscent
Copy link
Contributor Author

/run-all-tests

@Reminiscent
Copy link
Contributor Author

@qw4990 @rebelice @winoros PTAL. Thanks!

Copy link
Contributor

@rebelice rebelice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-srebot ti-srebot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 2, 2021
Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Feb 2, 2021
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Feb 2, 2021
@qw4990
Copy link
Contributor

qw4990 commented Feb 2, 2021

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 2, 2021
@ti-srebot
Copy link
Contributor

/run-all-tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sig/execution SIG execution sig/planner SIG: Planner status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants