Skip to content

Commit 796cbd0

Browse files
authored
Merge pull request #2859 from actiontech/2587
rule DMLCheckScanRowsDesc cancel checking of type of sql explain
2 parents 966b5a4 + b98ed81 commit 796cbd0

File tree

5 files changed

+9
-11
lines changed

5 files changed

+9
-11
lines changed

sqle/driver/mysql/audit_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6494,7 +6494,7 @@ func TestDMLCheckScanRows(t *testing.T) {
64946494
inspect3 := NewMockInspect(e)
64956495
handler.ExpectQuery(regexp.QuoteMeta("select * from exist_tb_2 where v1 = 'a'")).
64966496
WillReturnRows(sqlmock.NewRows([]string{"rows", "type"}).AddRow("100000000000", "const"))
6497-
runSingleRuleInspectCase(rule, t, "", inspect3, "select * from exist_tb_2 where v1 = 'a'", newTestResult())
6497+
runSingleRuleInspectCase(rule, t, "", inspect3, "select * from exist_tb_2 where v1 = 'a'", newTestResult().addResult(rulepkg.DMLCheckScanRows))
64986498

64996499
inspect4 := NewMockInspect(e)
65006500
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) {
65196519
inspect8 := NewMockInspect(e)
65206520
handler.ExpectQuery(regexp.QuoteMeta("update exist_tb_2 set v1=1 where v2=1")).
65216521
WillReturnRows(sqlmock.NewRows([]string{"rows", "type"}).AddRow("100000000", "range"))
6522-
runSingleRuleInspectCase(rule, t, "", inspect8, "update exist_tb_2 set v1=1 where v2=1", newTestResult())
6522+
runSingleRuleInspectCase(rule, t, "", inspect8, "update exist_tb_2 set v1=1 where v2=1", newTestResult().addResult(rulepkg.DMLCheckScanRows))
65236523

65246524
inspect9 := NewMockInspect(e)
65256525
handler.ExpectQuery(regexp.QuoteMeta("update exist_tb_2 set v1=1 where v2=1")).
@@ -6534,7 +6534,7 @@ func TestDMLCheckScanRows(t *testing.T) {
65346534
inspect11 := NewMockInspect(e)
65356535
handler.ExpectQuery(regexp.QuoteMeta("delete from exist_tb_2 where v1=1")).
65366536
WillReturnRows(sqlmock.NewRows([]string{"rows", "type"}).AddRow("100000000", "range"))
6537-
runSingleRuleInspectCase(rule, t, "", inspect11, "delete from exist_tb_2 where v1=1", newTestResult())
6537+
runSingleRuleInspectCase(rule, t, "", inspect11, "delete from exist_tb_2 where v1=1", newTestResult().addResult(rulepkg.DMLCheckScanRows))
65386538
}
65396539

65406540
// TODO

sqle/driver/mysql/plocale/active.en.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ DMLCheckSameTableJoinedMultipleTimesAnnotation = "If a single table is queried m
388388
DMLCheckSameTableJoinedMultipleTimesDesc = "It is not recommended to join the same table multiple times"
389389
DMLCheckSameTableJoinedMultipleTimesMessage = "Table %v is joined multiple times"
390390
DMLCheckScanRowsAnnotation = "The filter condition must include the primary key or index to reduce the time complexity of the database query and improve query efficiency."
391-
DMLCheckScanRowsDesc = "The number of rows scanned exceeds the threshold, the filter condition must include the primary key or index"
392-
DMLCheckScanRowsMessage = "The number of rows scanned exceeds the threshold, the filter condition must include the primary key or index"
391+
DMLCheckScanRowsDesc = "The number of rows scanned exceeds the threshold, please check the index configuration."
392+
DMLCheckScanRowsMessage = "The number of rows scanned exceeds the threshold, please check the index configuration."
393393
DMLCheckScanRowsParams1 = "Number of rows scanned (ten thousand)"
394394
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."
395395
DMLCheckSelectForUpdateDesc = "It is not recommended to use SELECT FOR UPDATE"

sqle/driver/mysql/plocale/active.zh.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ DMLCheckSameTableJoinedMultipleTimesAnnotation = "如果对单表查询多次,
388388
DMLCheckSameTableJoinedMultipleTimesDesc = "不建议对同一张表连接多次"
389389
DMLCheckSameTableJoinedMultipleTimesMessage = "表%v被连接多次"
390390
DMLCheckScanRowsAnnotation = "筛选条件必须带上主键或索引可降低数据库查询的时间复杂度,提高查询效率。"
391-
DMLCheckScanRowsDesc = "扫描行数超过阈值,筛选条件必须带上主键或者索引"
392-
DMLCheckScanRowsMessage = "扫描行数超过阈值,筛选条件必须带上主键或者索引"
391+
DMLCheckScanRowsDesc = "扫描行数超过阈值,请检查索引配置"
392+
DMLCheckScanRowsMessage = "扫描行数超过阈值,请检查索引配置"
393393
DMLCheckScanRowsParams1 = "扫描行数量(万)"
394394
DMLCheckSelectForUpdateAnnotation = "SELECT FOR UPDATE 会对查询结果集中每行数据都添加排他锁,其他线程对该记录的更新与删除操作都会阻塞,在高并发下,容易造成数据库大量锁等待,影响数据库查询性能"
395395
DMLCheckSelectForUpdateDesc = "不建议使用SELECT FOR UPDATE"

sqle/driver/mysql/plocale/message_zh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,9 +611,9 @@ var (
611611
DMLCheckSelectRowsAnnotation = &i18n.Message{ID: "DMLCheckSelectRowsAnnotation", Other: "筛选条件必须带上主键或索引可提高查询性能和减少全表扫描的成本。"}
612612
DMLCheckSelectRowsMessage = &i18n.Message{ID: "DMLCheckSelectRowsMessage", Other: "查询数据量超过阈值,筛选条件必须带上主键或者索引"}
613613
DMLCheckSelectRowsParams1 = &i18n.Message{ID: "DMLCheckSelectRowsParams1", Other: "查询数据量(万)"}
614-
DMLCheckScanRowsDesc = &i18n.Message{ID: "DMLCheckScanRowsDesc", Other: "扫描行数超过阈值,筛选条件必须带上主键或者索引"}
614+
DMLCheckScanRowsDesc = &i18n.Message{ID: "DMLCheckScanRowsDesc", Other: "扫描行数超过阈值,请检查索引配置"}
615615
DMLCheckScanRowsAnnotation = &i18n.Message{ID: "DMLCheckScanRowsAnnotation", Other: "筛选条件必须带上主键或索引可降低数据库查询的时间复杂度,提高查询效率。"}
616-
DMLCheckScanRowsMessage = &i18n.Message{ID: "DMLCheckScanRowsMessage", Other: "扫描行数超过阈值,筛选条件必须带上主键或者索引"}
616+
DMLCheckScanRowsMessage = &i18n.Message{ID: "DMLCheckScanRowsMessage", Other: "扫描行数超过阈值,请检查索引配置"}
617617
DMLCheckScanRowsParams1 = &i18n.Message{ID: "DMLCheckScanRowsParams1", Other: "扫描行数量(万)"}
618618
DMLMustUseLeftMostPrefixDesc = &i18n.Message{ID: "DMLMustUseLeftMostPrefixDesc", Other: "使用联合索引时,必须使用联合索引的首字段"}
619619
DMLMustUseLeftMostPrefixAnnotation = &i18n.Message{ID: "DMLMustUseLeftMostPrefixAnnotation", Other: "使用联合索引时,不包含首字段会导致联合索引失效"}

sqle/driver/mysql/rule/rule.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5203,10 +5203,8 @@ func checkScanRows(input *RuleHandlerInput) error {
52035203
}
52045204
for _, record := range epRecords {
52055205
if record.Rows > int64(max)*int64(TenThousand) {
5206-
if record.Type == executor.ExplainRecordAccessTypeIndex || record.Type == executor.ExplainRecordAccessTypeAll {
52075206
addResult(input.Res, input.Rule, input.Rule.Name)
52085207
break
5209-
}
52105208
}
52115209
}
52125210
return nil

0 commit comments

Comments
 (0)