Skip to content

Commit 718c7bb

Browse files
authored
Merge pull request #3081 from actiontech/fix_not_null_rule
fix: not null rule when blob text
2 parents 8ff68b1 + e9d5b6e commit 718c7bb

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

sqle/driver/mysql/rule/rule.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4924,15 +4924,15 @@ func checkColumnNotNull(input *RuleHandlerInput) error {
49244924
for _, spec := range stmt.Specs {
49254925
for _, newColumn := range spec.NewColumns {
49264926
ok := util.IsAllInOptions(newColumn.Options, ast.ColumnOptionNotNull)
4927-
if !ok {
4927+
if !ok && !isBlob(newColumn) {
49284928
notNullColumns = append(notNullColumns, newColumn.Name.OrigColName())
49294929
}
49304930
}
49314931
}
49324932
case *ast.CreateTableStmt:
49334933
for _, col := range stmt.Cols {
49344934
ok := util.IsAllInOptions(col.Options, ast.ColumnOptionNotNull)
4935-
if !ok {
4935+
if !ok && !isBlob(col) {
49364936
notNullColumns = append(notNullColumns, col.Name.OrigColName())
49374937
}
49384938
}
@@ -4944,6 +4944,17 @@ func checkColumnNotNull(input *RuleHandlerInput) error {
49444944
return nil
49454945
}
49464946

4947+
func isBlob(columnDef *ast.ColumnDef) bool {
4948+
if columnDef.Tp == nil {
4949+
return false
4950+
}
4951+
switch columnDef.Tp.Tp {
4952+
case mysql.TypeBlob, mysql.TypeMediumBlob, mysql.TypeTinyBlob, mysql.TypeLongBlob:
4953+
return true
4954+
}
4955+
return false
4956+
}
4957+
49474958
func checkIndexSelectivity(input *RuleHandlerInput) error {
49484959
if _, ok := input.Node.(*ast.SelectStmt); !ok {
49494960
return nil

0 commit comments

Comments
 (0)