-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
statistics: refactor package. #2913
Changes from 7 commits
6fefdd7
67e1a81
4d46d80
ee5cb61
3802853
6727662
5effd89
e21cb33
49ea57a
117fe39
30d13db
cfde810
915a8b1
9ad30a3
fc8c164
ce6261d
effb848
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,14 +116,38 @@ const ( | |
UNIQUE KEY name (name) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT='help topics';` | ||
|
||
// CreateStatsMetaTable store's the meta of table statistics. | ||
// CreateStatsMetaTable stores the meta of table statistics. | ||
CreateStatsMetaTable = `CREATE TABLE if not exists mysql.stats_meta ( | ||
version bigint(64) unsigned NOT NULL, | ||
table_id bigint(64) NOT NULL, | ||
modify_count bigint(64) NOT NULL DEFAULT 0, | ||
count bigint(64) unsigned NOT NULL DEFAULT 0, | ||
index idx_ver(version) | ||
);` | ||
|
||
// CreateStatsColsTable stores the statistics of table columns. | ||
CreateStatsColsTable = `CREATE TABLE if not exists mysql.stats_columns ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about name the table |
||
table_id bigint(64) NOT NULL, | ||
col_id bigint(64), | ||
index_id bigint(64), | ||
distinct_count bigint(64) NOT NULL, | ||
distinct_ratio double(64) NOT NULL DEFAULT 0, | ||
use_count_to_estimate tinyint(2) NOT NULL DEFAULT 0, | ||
version bigint(64) unsigned NOT NULL DEFAULT 0, | ||
index tbl(table_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unique tbl(table_id, col_id, index_id)? |
||
);` | ||
|
||
// CreateStatsBucketsTable stores the histogram info for every table columns. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to point out that the |
||
CreateStatsBucketsTable = `CREATE TABLE if not exists mysql.stats_buckets ( | ||
table_id bigint(64) NOT NULL, | ||
col_id bigint(64), | ||
index_id bigint(64), | ||
bucket_id bigint(64) NOT NULL, | ||
count bigint(64) NOT NULL, | ||
repeats bigint(64) NOT NULL, | ||
value blob NOT NULL, | ||
index tbl(table_id, col_id, index_id, bucket_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be unique. |
||
);` | ||
) | ||
|
||
// Bootstrap initiates system DB for a store. | ||
|
@@ -153,6 +177,7 @@ const ( | |
version2 = 2 | ||
version3 = 3 | ||
version4 = 4 | ||
version5 = 5 | ||
) | ||
|
||
func checkBootstrapped(s Session) (bool, error) { | ||
|
@@ -226,6 +251,10 @@ func upgrade(s Session) { | |
upgradeToVer4(s) | ||
} | ||
|
||
if ver < version5 { | ||
upgradeToVer5(s) | ||
} | ||
|
||
updateBootstrapVer(s) | ||
_, err = s.Execute("COMMIT") | ||
|
||
|
@@ -279,6 +308,11 @@ func upgradeToVer4(s Session) { | |
mustExecute(s, sql) | ||
} | ||
|
||
func upgradeToVer5(s Session) { | ||
mustExecute(s, CreateStatsColsTable) | ||
mustExecute(s, CreateStatsBucketsTable) | ||
} | ||
|
||
// Update boostrap version variable in mysql.TiDB table. | ||
func updateBootstrapVer(s Session) { | ||
// Update bootstrap version. | ||
|
@@ -319,6 +353,10 @@ func doDDLWorks(s Session) { | |
mustExecute(s, CreateHelpTopic) | ||
// Create stats_meta table. | ||
mustExecute(s, CreateStatsMetaTable) | ||
// Create stats_columns table. | ||
mustExecute(s, CreateStatsColsTable) | ||
// Create stats_buckets table. | ||
mustExecute(s, CreateStatsBucketsTable) | ||
} | ||
|
||
// Execute DML statements in bootstrap stage. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need an index for table_id.