-
Notifications
You must be signed in to change notification settings - Fork 187
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
feat: 新增MySQL规则 #2753
Conversation
sqle/driver/mysql/rule/rule.go
Outdated
if !tableExist || err != nil { | ||
return err |
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.
如果table不存在,那error会不等于nil吗?
这是两种情况,都用返回error处理可以吗
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.
如果表不存在,返回error,会不会导致审核阻塞?
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.
嗯 这里有问题
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)) | ||
} |
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.
除了正则匹配还有其他方法吗?
这个正则无法匹配换行的情况
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.
暂时没有,目前的语法树解析不支持。这个做法是参照event
那个规则做的。
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.
增加一下单测吧,看看是不是都能匹配
- 单行的
- 换行的
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.
增加了单测,通过。
sqle/driver/mysql/rule/rule.go
Outdated
@@ -5239,7 +5238,10 @@ func checkTableRowLength(input *RuleHandlerInput) error { | |||
continue | |||
} | |||
// 可能会设置列级别的字符串 |
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.
不理解这个注释的含义
注释+代码,需要能够说明这里为什么这么做,做了什么
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.
增加注释
@@ -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() |
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.
若表实际的页长小于人工设置的页长,则该规则失效
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.
补充进文档
return charsetNum | ||
} | ||
|
||
// ComputeOneColumnLength 计算一个列的长度 |
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.
贴一下长度计算的依据:
- 官方文档
- 用ai使用mysql的风格格式绘制一个表格放在这里
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.
增加了注释
关联的 issue
#2732
描述你的变更
确认项(pr提交后操作)
Tip
请在指定复审人之前,确认并完成以下事项,完成后✅
not_compatible
need_update_doc