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

perf: the performance of calculating index selectivity #1938

Merged
merged 17 commits into from
Oct 26, 2023
Merged

perf: the performance of calculating index selectivity #1938

merged 17 commits into from
Oct 26, 2023

Conversation

winfredLIN
Copy link
Collaborator

#1918
optimize the performance of calculate index selectivity in the case of large tables

modify test case of rules about index selectivity

@winfredLIN winfredLIN requested a review from sjjian October 20, 2023 10:55
Comment on lines 667 to 677
func queryValue(schema, table, index string) string {
return fmt.Sprintf("('%s', '%s', '%s')", schema, table, index)
}

func indexSelectivity(queryValues []string) string {
return fmt.Sprintf(
`SELECT (s.CARDINALITY / t.TABLE_ROWS) AS index_selectivity FROM INFORMATION_SCHEMA.STATISTICS s JOIN INFORMATION_SCHEMA.TABLES t ON s.TABLE_SCHEMA = t.TABLE_SCHEMA AND s.TABLE_NAME = t.TABLE_NAME WHERE (s.TABLE_SCHEMA , s.TABLE_NAME , s.COLUMN_NAME) IN (%s);`,
strings.Join(queryValues, ","),
)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

在给出三星索引建议的规则中,也需要获取到列的选择性,这里会考虑将其重构成更通用的工具方法

Comment on lines 1428 to 1430
Message: "索引字段 %v 未超过区分度阈值 百分之%v, 不建议选为索引字段",
AllowOffline: false,
Func: checkIndexOption,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

修改了名称,在DDL语句中,对添加/修改索引的操作,检查的是添加的索引字段的区分度,细粒度到某一列


results, err := c.e.Db.Query(
fmt.Sprintf(
"SELECT %v FROM (SELECT %v FROM %v.%v LIMIT 50000) t;",
Copy link
Member

Choose a reason for hiding this comment

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

这里使用子查询是否有必要性

@sjjian sjjian merged commit 718e227 into main Oct 26, 2023
2 checks passed
@sjjian sjjian deleted the issue1918 branch October 26, 2023 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants