Skip to content

Commit 9a8f313

Browse files
author
ffffwh
committed
fix an alter table error #1036
when mysql lower_case_table_names = 1.
1 parent 77b459f commit 9a8f313

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

driver/mysql/binlog/binlog_reader.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,6 @@ func (b *BinlogReader) resolveQuery(currentSchema string, sql string,
10421042
result.isRecognized = false
10431043
return result, nil
10441044
}
1045-
result.ast = stmt
10461045

10471046
setSchema := func(schema *string) {
10481047
if b.lowerCaseTableNames != mysqlconfig.LowerCaseTableNames0 {
@@ -1120,11 +1119,12 @@ func (b *BinlogReader) resolveQuery(currentSchema string, sql string,
11201119
}
11211120

11221121
if len(newTables) == 0 {
1122+
// No tables included. Add the first table and ignore the whole stmt.
11231123
newTables = v.Tables[:1]
11241124
setTable(v.Tables[0], false)
11251125
}
11261126

1127-
if len(newTables) != len(v.Tables) {
1127+
if rewrite || len(newTables) != len(v.Tables) {
11281128
v.Tables = newTables
11291129
rewrite = true
11301130
}
@@ -1162,8 +1162,16 @@ func (b *BinlogReader) resolveQuery(currentSchema string, sql string,
11621162
}
11631163
result.sql = bs.String()
11641164
b.logger.Debug("resolveQuery. rewrite", "sql", result.sql)
1165+
1166+
// Re-generate ast. See #1036.
1167+
stmt, err = parser.New().ParseOneStmt(result.sql, "", "")
1168+
if err != nil {
1169+
return result, err
1170+
}
11651171
}
11661172

1173+
result.ast = stmt
1174+
11671175
return result, nil
11681176
}
11691177

0 commit comments

Comments
 (0)