-
Notifications
You must be signed in to change notification settings - Fork 186
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
Conversation
optimize the performance of calculate selectivity in the case of large tables @winfredLIN
sqle/driver/mysql/session/context.go
Outdated
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, ","), | ||
) | ||
} | ||
|
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.
在给出三星索引建议的规则中,也需要获取到列的选择性,这里会考虑将其重构成更通用的工具方法
use GetSelectivityOfColumns instead of GetMaxIndexOptionForTable in checkIndexOption use GetSelectivityOfIndex instead of GetMaxIndexOptionForTable in checkIndexSelectivity
rules: 1. DDLCheckIndexOption 2. DMLCheckIndexSelectivity
sqle/driver/mysql/rule/rule.go
Outdated
Message: "索引字段 %v 未超过区分度阈值 百分之%v, 不建议选为索引字段", | ||
AllowOffline: false, | ||
Func: checkIndexOption, |
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.
修改了名称,在DDL语句中,对添加/修改索引的操作,检查的是添加的索引字段的区分度,细粒度到某一列
|
||
results, err := c.e.Db.Query( | ||
fmt.Sprintf( | ||
"SELECT %v FROM (SELECT %v FROM %v.%v LIMIT 50000) t;", |
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.
这里使用子查询是否有必要性
#1918
optimize the performance of calculate index selectivity in the case of large tables
modify test case of rules about index selectivity