fixing mediumint unsigned problem

This commit is contained in:
Shlomi Noach 2017-01-10 09:57:42 +02:00
parent 67cfba3ce4
commit a07a6f8cf5
4 changed files with 22 additions and 5 deletions

View File

@ -529,6 +529,11 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL
columnsList.SetUnsigned(columnName) columnsList.SetUnsigned(columnName)
} }
} }
if strings.Contains(columnType, "mediumint") {
for _, columnsList := range columnsLists {
columnsList.GetColumn(columnName).Type = sql.MediumIntColumnType
}
}
if strings.Contains(columnType, "timestamp") { if strings.Contains(columnType, "timestamp") {
for _, columnsList := range columnsLists { for _, columnsList := range columnsLists {
columnsList.GetColumn(columnName).Type = sql.TimestampColumnType columnsList.GetColumn(columnName).Type = sql.TimestampColumnType
@ -541,7 +546,7 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL
} }
if strings.HasPrefix(columnType, "enum") { if strings.HasPrefix(columnType, "enum") {
for _, columnsList := range columnsLists { for _, columnsList := range columnsLists {
columnsList.GetColumn(columnName).Type = sql.EnumColumnValue columnsList.GetColumn(columnName).Type = sql.EnumColumnType
} }
} }
if charset := m.GetString("CHARACTER_SET_NAME"); charset != "" { if charset := m.GetString("CHARACTER_SET_NAME"); charset != "" {

View File

@ -258,7 +258,7 @@ func BuildUniqueKeyRangeEndPreparedQuery(databaseName, tableName string, uniqueK
uniqueKeyColumnDescending := make([]string, len(uniqueKeyColumnNames), len(uniqueKeyColumnNames)) uniqueKeyColumnDescending := make([]string, len(uniqueKeyColumnNames), len(uniqueKeyColumnNames))
for i, column := range uniqueKeyColumns.Columns() { for i, column := range uniqueKeyColumns.Columns() {
uniqueKeyColumnNames[i] = EscapeName(uniqueKeyColumnNames[i]) uniqueKeyColumnNames[i] = EscapeName(uniqueKeyColumnNames[i])
if column.Type == EnumColumnValue { if column.Type == EnumColumnType {
uniqueKeyColumnAscending[i] = fmt.Sprintf("concat(%s) asc", uniqueKeyColumnNames[i]) uniqueKeyColumnAscending[i] = fmt.Sprintf("concat(%s) asc", uniqueKeyColumnNames[i])
uniqueKeyColumnDescending[i] = fmt.Sprintf("concat(%s) desc", uniqueKeyColumnNames[i]) uniqueKeyColumnDescending[i] = fmt.Sprintf("concat(%s) desc", uniqueKeyColumnNames[i])
} else { } else {
@ -309,7 +309,7 @@ func buildUniqueKeyMinMaxValuesPreparedQuery(databaseName, tableName string, uni
uniqueKeyColumnOrder := make([]string, len(uniqueKeyColumnNames), len(uniqueKeyColumnNames)) uniqueKeyColumnOrder := make([]string, len(uniqueKeyColumnNames), len(uniqueKeyColumnNames))
for i, column := range uniqueKeyColumns.Columns() { for i, column := range uniqueKeyColumns.Columns() {
uniqueKeyColumnNames[i] = EscapeName(uniqueKeyColumnNames[i]) uniqueKeyColumnNames[i] = EscapeName(uniqueKeyColumnNames[i])
if column.Type == EnumColumnValue { if column.Type == EnumColumnType {
uniqueKeyColumnOrder[i] = fmt.Sprintf("concat(%s) %s", uniqueKeyColumnNames[i], order) uniqueKeyColumnOrder[i] = fmt.Sprintf("concat(%s) %s", uniqueKeyColumnNames[i], order)
} else { } else {
uniqueKeyColumnOrder[i] = fmt.Sprintf("%s %s", uniqueKeyColumnNames[i], order) uniqueKeyColumnOrder[i] = fmt.Sprintf("%s %s", uniqueKeyColumnNames[i], order)

View File

@ -18,9 +18,12 @@ const (
UnknownColumnType ColumnType = iota UnknownColumnType ColumnType = iota
TimestampColumnType = iota TimestampColumnType = iota
DateTimeColumnType = iota DateTimeColumnType = iota
EnumColumnValue = iota EnumColumnType = iota
MediumIntColumnType = iota
) )
const maxMediumintUnsigned int32 = 16777215
type TimezoneConvertion struct { type TimezoneConvertion struct {
ToTimezone string ToTimezone string
} }
@ -50,6 +53,14 @@ func (this *Column) convertArg(arg interface{}) interface{} {
return uint16(i) return uint16(i)
} }
if i, ok := arg.(int32); ok { if i, ok := arg.(int32); ok {
if this.Type == MediumIntColumnType {
// problem with mediumint is that it's a 3-byte type. There is no compatible golang type to match that.
// So to convert from negative to positive we'd need to convert the value manually
if i >= 0 {
return i
}
return uint32(maxMediumintUnsigned + i + 1)
}
return uint32(i) return uint32(i)
} }
if i, ok := arg.(int64); ok { if i, ok := arg.(int64); ok {

View File

@ -8,7 +8,7 @@ create table gh_ost_test (
column5 int(11) NOT NULL, column5 int(11) NOT NULL,
column6 int(11) NOT NULL, column6 int(11) NOT NULL,
PRIMARY KEY (id), PRIMARY KEY (id),
KEY c12_uix (column1, column2) KEY c12_ix (column1, column2)
) auto_increment=1; ) auto_increment=1;
drop event if exists gh_ost_test; drop event if exists gh_ost_test;
@ -23,5 +23,6 @@ create event gh_ost_test
begin begin
-- mediumint maxvalue: 16777215 (unsigned), 8388607 (signed) -- mediumint maxvalue: 16777215 (unsigned), 8388607 (signed)
insert into gh_ost_test values (NULL, 13382498, 536, 8388607, 3, 1483892217, 1483892218); insert into gh_ost_test values (NULL, 13382498, 536, 8388607, 3, 1483892217, 1483892218);
insert into gh_ost_test values (NULL, 13382498, 536, 8388607, 250, 1483892217, 1483892218);
insert into gh_ost_test values (NULL, 13382498, 536, 10000000, 3, 1483892217, 1483892218); insert into gh_ost_test values (NULL, 13382498, 536, 10000000, 3, 1483892217, 1483892218);
end ;; end ;;