Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(catalog): set nil pointer for DEFAULT NULL (#3048)

rebelice243223626270
diff --git a/plugin/advisor/catalog/walk_through.go b/plugin/advisor/catalog/walk_through.go
index 978ec684f1..2b7cf24b96 100644
--- a/plugin/advisor/catalog/walk_through.go
+++ b/plugin/advisor/catalog/walk_through.go
@@ -1192,11 +1192,13 @@ func (t *TableState) createColumn(ctx *FinderContext, column *tidbast.ColumnDef,
case tidbast.ColumnOptionAutoIncrement:
// we do not deal with AUTO-INCREMENT
case tidbast.ColumnOptionDefaultValue:
- defaultValue, err := restoreNode(option.Expr, format.RestoreStringWithoutCharset)
- if err != nil {
- return err
+ if option.Expr.GetType().GetType() != mysql.TypeNull {
+ defaultValue, err := restoreNode(option.Expr, format.RestoreStringWithoutCharset)
+ if err != nil {
+ return err
+ }
+ col.defaultValue = &defaultValue
}
- col.defaultValue = &defaultValue
case tidbast.ColumnOptionUniqKey:
if err := t.createIndex("", []string{col.name}, true /* unique */, model.IndexTypeBtree.String(), nil); err != nil {
return err
diff --git a/plugin/advisor/catalog/walk_through_test.go b/plugin/advisor/catalog/walk_through_test.go
index 168eca4379..35961130bf 100644
--- a/plugin/advisor/catalog/walk_through_test.go
+++ b/plugin/advisor/catalog/walk_through_test.go
@@ -301,7 +301,7 @@ func TestWalkThrough(t *testing.T) {
CREATE TABLE t(
a int PRIMARY KEY DEFAULT 1,
b varchar(200) CHARACTER SET utf8mb4 NOT NULL UNIQUE,
- c int auto_increment NULL COMMENT 'This is a comment',
+ c int auto_increment NULL COMMENT 'This is a comment' DEFAULT NULL,
d varchar(10) COLLATE utf8mb4_polish_ci,
KEY idx_a (a),
INDEX (b, a),