Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collect table statistics when importing data by Lightning #40469

Open
xuyifangreeneyes opened this issue Jan 10, 2023 · 1 comment
Open

collect table statistics when importing data by Lightning #40469

xuyifangreeneyes opened this issue Jan 10, 2023 · 1 comment
Labels
component/lightning This issue is related to Lightning of TiDB. component/statistics sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.

Comments

@xuyifangreeneyes
Copy link
Contributor

Enhancement

Currently, after we import data to the cluster, we need to analyze the table, which is time-consuming since it needs to scan the whole table. Collecting table statistics can be done when iterating all the data. There are several steps in Lightning that iterate all the data, such as scanning CSV files, passing KV values streamingly from Lightning to TiKV, and checksum. Hence collecting table statistics can be done in any of those steps to avoid another table full scan.

@xuyifangreeneyes xuyifangreeneyes added type/enhancement The issue or PR belongs to an enhancement. sig/planner SIG: Planner component/statistics component/lightning This issue is related to Lightning of TiDB. labels Jan 10, 2023
@lance6716
Copy link
Contributor

Write some notes about my understanding. Lightning should integrate these actions (take adding index as example):

  1. maintain Count-Min Sketch, Flajolet–Martin Sketch, Histogram for each import chunk
    https://github.com/tikv/tikv/blob/321aa833ca5ec0fd5dcec7fa8c01f65116d72ba6/src/coprocessor/statistics/analyze.rs#L145-L188

  2. update statistics for whole table from multiple per-chunk statistics

    func (e *AnalyzeIndexExec) buildStatsFromResult(result distsql.SelectResult, needCMS bool) (*statistics.Histogram, *statistics.CMSketch, *statistics.FMSketch, *statistics.TopN, error) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/lightning This issue is related to Lightning of TiDB. component/statistics sig/planner SIG: Planner type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

2 participants