diff --git a/sqle/driver/mysql/audit_test.go b/sqle/driver/mysql/audit_test.go index 1c4601343..5a6deae37 100644 --- a/sqle/driver/mysql/audit_test.go +++ b/sqle/driver/mysql/audit_test.go @@ -6494,7 +6494,7 @@ func TestDMLCheckScanRows(t *testing.T) { inspect3 := NewMockInspect(e) handler.ExpectQuery(regexp.QuoteMeta("select * from exist_tb_2 where v1 = 'a'")). WillReturnRows(sqlmock.NewRows([]string{"rows", "type"}).AddRow("100000000000", "const")) - runSingleRuleInspectCase(rule, t, "", inspect3, "select * from exist_tb_2 where v1 = 'a'", newTestResult()) + runSingleRuleInspectCase(rule, t, "", inspect3, "select * from exist_tb_2 where v1 = 'a'", newTestResult().addResult(rulepkg.DMLCheckScanRows)) inspect4 := NewMockInspect(e) handler.ExpectQuery(regexp.QuoteMeta("select * from exist_tb_2 where v1 in (select v2 from exist_tb_1)")). @@ -6519,7 +6519,7 @@ func TestDMLCheckScanRows(t *testing.T) { inspect8 := NewMockInspect(e) handler.ExpectQuery(regexp.QuoteMeta("update exist_tb_2 set v1=1 where v2=1")). WillReturnRows(sqlmock.NewRows([]string{"rows", "type"}).AddRow("100000000", "range")) - runSingleRuleInspectCase(rule, t, "", inspect8, "update exist_tb_2 set v1=1 where v2=1", newTestResult()) + runSingleRuleInspectCase(rule, t, "", inspect8, "update exist_tb_2 set v1=1 where v2=1", newTestResult().addResult(rulepkg.DMLCheckScanRows)) inspect9 := NewMockInspect(e) handler.ExpectQuery(regexp.QuoteMeta("update exist_tb_2 set v1=1 where v2=1")). @@ -6534,7 +6534,7 @@ func TestDMLCheckScanRows(t *testing.T) { inspect11 := NewMockInspect(e) handler.ExpectQuery(regexp.QuoteMeta("delete from exist_tb_2 where v1=1")). WillReturnRows(sqlmock.NewRows([]string{"rows", "type"}).AddRow("100000000", "range")) - runSingleRuleInspectCase(rule, t, "", inspect11, "delete from exist_tb_2 where v1=1", newTestResult()) + runSingleRuleInspectCase(rule, t, "", inspect11, "delete from exist_tb_2 where v1=1", newTestResult().addResult(rulepkg.DMLCheckScanRows)) } // TODO diff --git a/sqle/driver/mysql/plocale/active.en.toml b/sqle/driver/mysql/plocale/active.en.toml index 57fd6ae80..eed6bf354 100644 --- a/sqle/driver/mysql/plocale/active.en.toml +++ b/sqle/driver/mysql/plocale/active.en.toml @@ -388,8 +388,8 @@ DMLCheckSameTableJoinedMultipleTimesAnnotation = "If a single table is queried m DMLCheckSameTableJoinedMultipleTimesDesc = "It is not recommended to join the same table multiple times" DMLCheckSameTableJoinedMultipleTimesMessage = "Table %v is joined multiple times" DMLCheckScanRowsAnnotation = "The filter condition must include the primary key or index to reduce the time complexity of the database query and improve query efficiency." -DMLCheckScanRowsDesc = "The number of rows scanned exceeds the threshold, the filter condition must include the primary key or index" -DMLCheckScanRowsMessage = "The number of rows scanned exceeds the threshold, the filter condition must include the primary key or index" +DMLCheckScanRowsDesc = "The number of rows scanned exceeds the threshold, please check the index configuration." +DMLCheckScanRowsMessage = "The number of rows scanned exceeds the threshold, please check the index configuration." DMLCheckScanRowsParams1 = "Number of rows scanned (ten thousand)" DMLCheckSelectForUpdateAnnotation = "SELECT FOR UPDATE will add an exclusive lock to each row of data in the query result set. Other threads will be blocked from updating and deleting the record, which can easily lead to a large number of lock waits in the database under high concurrency, affecting database query performance." DMLCheckSelectForUpdateDesc = "It is not recommended to use SELECT FOR UPDATE" diff --git a/sqle/driver/mysql/plocale/active.zh.toml b/sqle/driver/mysql/plocale/active.zh.toml index aa4d33ac3..3a7f63370 100644 --- a/sqle/driver/mysql/plocale/active.zh.toml +++ b/sqle/driver/mysql/plocale/active.zh.toml @@ -388,8 +388,8 @@ DMLCheckSameTableJoinedMultipleTimesAnnotation = "如果对单表查询多次, DMLCheckSameTableJoinedMultipleTimesDesc = "不建议对同一张表连接多次" DMLCheckSameTableJoinedMultipleTimesMessage = "表%v被连接多次" DMLCheckScanRowsAnnotation = "筛选条件必须带上主键或索引可降低数据库查询的时间复杂度,提高查询效率。" -DMLCheckScanRowsDesc = "扫描行数超过阈值,筛选条件必须带上主键或者索引" -DMLCheckScanRowsMessage = "扫描行数超过阈值,筛选条件必须带上主键或者索引" +DMLCheckScanRowsDesc = "扫描行数超过阈值,请检查索引配置" +DMLCheckScanRowsMessage = "扫描行数超过阈值,请检查索引配置" DMLCheckScanRowsParams1 = "扫描行数量(万)" DMLCheckSelectForUpdateAnnotation = "SELECT FOR UPDATE 会对查询结果集中每行数据都添加排他锁,其他线程对该记录的更新与删除操作都会阻塞,在高并发下,容易造成数据库大量锁等待,影响数据库查询性能" DMLCheckSelectForUpdateDesc = "不建议使用SELECT FOR UPDATE" diff --git a/sqle/driver/mysql/plocale/message_zh.go b/sqle/driver/mysql/plocale/message_zh.go index 3543948e9..de6727d31 100644 --- a/sqle/driver/mysql/plocale/message_zh.go +++ b/sqle/driver/mysql/plocale/message_zh.go @@ -611,9 +611,9 @@ var ( DMLCheckSelectRowsAnnotation = &i18n.Message{ID: "DMLCheckSelectRowsAnnotation", Other: "筛选条件必须带上主键或索引可提高查询性能和减少全表扫描的成本。"} DMLCheckSelectRowsMessage = &i18n.Message{ID: "DMLCheckSelectRowsMessage", Other: "查询数据量超过阈值,筛选条件必须带上主键或者索引"} DMLCheckSelectRowsParams1 = &i18n.Message{ID: "DMLCheckSelectRowsParams1", Other: "查询数据量(万)"} - DMLCheckScanRowsDesc = &i18n.Message{ID: "DMLCheckScanRowsDesc", Other: "扫描行数超过阈值,筛选条件必须带上主键或者索引"} + DMLCheckScanRowsDesc = &i18n.Message{ID: "DMLCheckScanRowsDesc", Other: "扫描行数超过阈值,请检查索引配置"} DMLCheckScanRowsAnnotation = &i18n.Message{ID: "DMLCheckScanRowsAnnotation", Other: "筛选条件必须带上主键或索引可降低数据库查询的时间复杂度,提高查询效率。"} - DMLCheckScanRowsMessage = &i18n.Message{ID: "DMLCheckScanRowsMessage", Other: "扫描行数超过阈值,筛选条件必须带上主键或者索引"} + DMLCheckScanRowsMessage = &i18n.Message{ID: "DMLCheckScanRowsMessage", Other: "扫描行数超过阈值,请检查索引配置"} DMLCheckScanRowsParams1 = &i18n.Message{ID: "DMLCheckScanRowsParams1", Other: "扫描行数量(万)"} DMLMustUseLeftMostPrefixDesc = &i18n.Message{ID: "DMLMustUseLeftMostPrefixDesc", Other: "使用联合索引时,必须使用联合索引的首字段"} DMLMustUseLeftMostPrefixAnnotation = &i18n.Message{ID: "DMLMustUseLeftMostPrefixAnnotation", Other: "使用联合索引时,不包含首字段会导致联合索引失效"} diff --git a/sqle/driver/mysql/rule/rule.go b/sqle/driver/mysql/rule/rule.go index 171d53a82..9842a2dcc 100644 --- a/sqle/driver/mysql/rule/rule.go +++ b/sqle/driver/mysql/rule/rule.go @@ -5203,10 +5203,8 @@ func checkScanRows(input *RuleHandlerInput) error { } for _, record := range epRecords { if record.Rows > int64(max)*int64(TenThousand) { - if record.Type == executor.ExplainRecordAccessTypeIndex || record.Type == executor.ExplainRecordAccessTypeAll { addResult(input.Res, input.Rule, input.Rule.Name) break - } } } return nil