Skip to content

Commit

Permalink
drainer: Ignore generated columns when updating (#515)
Browse files Browse the repository at this point in the history
  • Loading branch information
suzaku authored Apr 4, 2019
1 parent 860b89c commit eb7fea0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
4 changes: 2 additions & 2 deletions drainer/translator/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (m *mysqlTranslator) GenUpdateSQLs(schema string, table *model.TableInfo, r
return sqls, keys, values, safeMode, err
}

columns := table.Columns
columns := writableColumns(table)
sqls := make([]string, 0, len(rows))
keys := make([][]string, 0, len(rows))
values := make([][]interface{}, 0, len(rows))
Expand Down Expand Up @@ -167,7 +167,7 @@ func (m *mysqlTranslator) GenUpdateSQLs(schema string, table *model.TableInfo, r
}

func (m *mysqlTranslator) genUpdateSQLsSafeMode(schema string, table *model.TableInfo, rows [][]byte, commitTS int64) ([]string, [][]string, [][]interface{}, error) {
columns := table.Columns
columns := writableColumns(table)
sqls := make([]string, 0, len(rows))
keys := make([][]string, 0, len(rows))
values := make([][]interface{}, 0, len(rows))
Expand Down
2 changes: 1 addition & 1 deletion drainer/translator/pb.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (p *pbTranslator) GenInsertSQLs(schema string, table *model.TableInfo, rows
}

func (p *pbTranslator) GenUpdateSQLs(schema string, table *model.TableInfo, rows [][]byte, commitTS int64) ([]string, [][]string, [][]interface{}, bool, error) {
columns := table.Columns
columns := writableColumns(table)
sqls := make([]string, 0, len(rows))
keys := make([][]string, 0, len(rows))
values := make([][]interface{}, 0, len(rows))
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (l *StdLogger) Println(v ...interface{}) {

// ToColumnTypeMap return a map index by column id
func ToColumnTypeMap(columns []*model.ColumnInfo) map[int64]*types.FieldType {
colTypeMap := make(map[int64]*types.FieldType)
colTypeMap := make(map[int64]*types.FieldType, len(columns))
for _, col := range columns {
colTypeMap[col.ID] = &col.FieldType
}
Expand Down
12 changes: 11 additions & 1 deletion tests/gencol/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ check_contains 'sum(a): 12'
check_contains 'sum(b): 62'
check_contains 'sum(c): 52'

run_sql 'UPDATE gencol.gct SET c = b WHERE a = 7;'

sleep 3

down_run_sql 'SELECT count(*), sum(a), sum(b), sum(c) FROM gencol.gct;'
check_contains 'count(*): 3'
check_contains 'sum(a): 12'
check_contains 'sum(b): 62'
check_contains 'sum(c): 93'

# Verify DELETE statements works with generated columns...

run_sql 'DELETE FROM gencol.gct WHERE b = 9;'
Expand All @@ -45,6 +55,6 @@ down_run_sql 'SELECT count(*), sum(a), sum(b), sum(c) FROM gencol.gct;'
check_contains 'count(*): 2'
check_contains 'sum(a): 9'
check_contains 'sum(b): 53'
check_contains 'sum(c): 20'
check_contains 'sum(c): 61'

killall drainer

0 comments on commit eb7fea0

Please sign in to comment.