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

feat: 新增MySQL规则 #2753

Merged
merged 11 commits into from
Nov 25, 2024
Merged

feat: 新增MySQL规则 #2753

merged 11 commits into from
Nov 25, 2024

Conversation

littleniannian
Copy link
Collaborator

@littleniannian littleniannian commented Nov 13, 2024

关联的 issue

#2732

描述你的变更

  • 新增四条mysql规则

确认项(pr提交后操作)

Tip

请在指定复审人之前,确认并完成以下事项,完成后✅


  • 我已完成自测
  • 我已在关联的issue里补充了实现方案
  • 我已在关联的issue里补充了测试影响面
  • 我已确认了变更的兼容性,如果不兼容则在issue里标记 not_compatible
  • 我已确认了是否要更新文档,如果要更新则在issue里标记 need_update_doc

Comment on lines 5192 to 5193
if !tableExist || err != nil {
return err
Copy link
Collaborator

Choose a reason for hiding this comment

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

如果table不存在,那error会不等于nil吗?
这是两种情况,都用返回error处理可以吗

Copy link
Collaborator

Choose a reason for hiding this comment

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

如果表不存在,返回error,会不会导致审核阻塞?

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 +211 to +215
func IsOpenEventScheduler(sql string) bool {
pattern := `(?i)^SET\s+GLOBAL\s+event_scheduler\s*=\s*(ON|1)\s*;`
reg := regexp.MustCompile(pattern)
return reg.MatchString(strings.TrimSpace(sql))
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

除了正则匹配还有其他方法吗?
这个正则无法匹配换行的情况

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

暂时没有,目前的语法树解析不支持。这个做法是参照event那个规则做的。

Copy link
Collaborator

Choose a reason for hiding this comment

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

增加一下单测吧,看看是不是都能匹配

  1. 单行的
  2. 换行的

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

增加了单测,通过。

@@ -5239,7 +5238,10 @@ func checkTableRowLength(input *RuleHandlerInput) error {
continue
}
// 可能会设置列级别的字符串
Copy link
Collaborator

Choose a reason for hiding this comment

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

不理解这个注释的含义
注释+代码,需要能够说明这里为什么这么做,做了什么

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

增加注释

@@ -5149,3 +5170,191 @@ func checkIndexNameExisted(input *RuleHandlerInput) error {
func IsIndexConstraint(constraintType ast.ConstraintType) bool {
return constraintType == ast.ConstraintIndex || constraintType == ast.ConstraintUniqIndex || constraintType == ast.ConstraintKey || constraintType == ast.ConstraintUniqKey
}

func checkTableRowLength(input *RuleHandlerInput) error {
var rowLengthLimit = input.Rule.Params.GetParam(DefaultSingleParamKeyName).Int()
Copy link
Collaborator

Choose a reason for hiding this comment

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

若表实际的页长小于人工设置的页长,则该规则失效

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

补充进文档

return charsetNum
}

// ComputeOneColumnLength 计算一个列的长度
Copy link
Collaborator

@winfredLIN winfredLIN Nov 22, 2024

Choose a reason for hiding this comment

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

贴一下长度计算的依据:

  1. 官方文档
  2. 用ai使用mysql的风格格式绘制一个表格放在这里

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

增加了注释

@sjjian sjjian merged commit e4c828b into release-2.2302.x Nov 25, 2024
3 checks passed
@sjjian sjjian deleted the feat_mysql_rule branch November 25, 2024 02:43
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.

3 participants