dropped columns are not 'shared' and no data copy attempted for such columns

This commit is contained in:
Shlomi Noach 2017-04-23 08:38:35 +03:00
parent b0469b95b5
commit 8a0f1413eb
4 changed files with 13 additions and 0 deletions

View File

@ -181,6 +181,7 @@ type MigrationContext struct {
UniqueKey *sql.UniqueKey
SharedColumns *sql.ColumnList
ColumnRenameMap map[string]string
DroppedColumnsMap map[string]bool
MappedSharedColumns *sql.ColumnList
MigrationRangeMinValues *sql.ColumnValues
MigrationRangeMaxValues *sql.ColumnValues

View File

@ -662,7 +662,14 @@ func (this *Inspector) getSharedColumns(originalColumns, ghostColumns *sql.Colum
}
sharedColumnNames := []string{}
for _, originalColumn := range originalColumns.Names() {
isSharedColumn := false
if columnsInGhost[originalColumn] || columnsInGhost[columnRenameMap[originalColumn]] {
isSharedColumn = true
}
if this.migrationContext.DroppedColumnsMap[originalColumn] {
isSharedColumn = false
}
if isSharedColumn {
sharedColumnNames = append(sharedColumnNames, originalColumn)
}
}

View File

@ -248,6 +248,7 @@ func (this *Migrator) validateStatement() (err error) {
}
log.Infof("Alter statement has column(s) renamed. gh-ost finds the following renames: %v; --approve-renamed-columns is given and so migration proceeds.", this.parser.GetNonTrivialRenames())
}
this.migrationContext.DroppedColumnsMap = this.parser.DroppedColumnsMap()
return nil
}

View File

@ -111,3 +111,7 @@ func (this *Parser) GetNonTrivialRenames() map[string]string {
func (this *Parser) HasNonTrivialRenames() bool {
return len(this.GetNonTrivialRenames()) > 0
}
func (this *Parser) DroppedColumnsMap() map[string]bool {
return this.droppedColumns
}