Skip to content

Commit 5af7026

Browse files
author
Shlomi Noach
authored
Merge pull request #355 from github/unsigned-int
localtests and fix for unsigned medium int problem
2 parents 31ba582 + 56ab127 commit 5af7026

5 files changed

Lines changed: 49 additions & 5 deletions

File tree

RELEASE_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.34
1+
1.0.35

go/logic/inspect.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,11 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL
529529
columnsList.SetUnsigned(columnName)
530530
}
531531
}
532+
if strings.Contains(columnType, "mediumint") {
533+
for _, columnsList := range columnsLists {
534+
columnsList.GetColumn(columnName).Type = sql.MediumIntColumnType
535+
}
536+
}
532537
if strings.Contains(columnType, "timestamp") {
533538
for _, columnsList := range columnsLists {
534539
columnsList.GetColumn(columnName).Type = sql.TimestampColumnType
@@ -541,7 +546,7 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL
541546
}
542547
if strings.HasPrefix(columnType, "enum") {
543548
for _, columnsList := range columnsLists {
544-
columnsList.GetColumn(columnName).Type = sql.EnumColumnValue
549+
columnsList.GetColumn(columnName).Type = sql.EnumColumnType
545550
}
546551
}
547552
if charset := m.GetString("CHARACTER_SET_NAME"); charset != "" {

go/sql/builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func BuildUniqueKeyRangeEndPreparedQuery(databaseName, tableName string, uniqueK
258258
uniqueKeyColumnDescending := make([]string, len(uniqueKeyColumnNames), len(uniqueKeyColumnNames))
259259
for i, column := range uniqueKeyColumns.Columns() {
260260
uniqueKeyColumnNames[i] = EscapeName(uniqueKeyColumnNames[i])
261-
if column.Type == EnumColumnValue {
261+
if column.Type == EnumColumnType {
262262
uniqueKeyColumnAscending[i] = fmt.Sprintf("concat(%s) asc", uniqueKeyColumnNames[i])
263263
uniqueKeyColumnDescending[i] = fmt.Sprintf("concat(%s) desc", uniqueKeyColumnNames[i])
264264
} else {
@@ -309,7 +309,7 @@ func buildUniqueKeyMinMaxValuesPreparedQuery(databaseName, tableName string, uni
309309
uniqueKeyColumnOrder := make([]string, len(uniqueKeyColumnNames), len(uniqueKeyColumnNames))
310310
for i, column := range uniqueKeyColumns.Columns() {
311311
uniqueKeyColumnNames[i] = EscapeName(uniqueKeyColumnNames[i])
312-
if column.Type == EnumColumnValue {
312+
if column.Type == EnumColumnType {
313313
uniqueKeyColumnOrder[i] = fmt.Sprintf("concat(%s) %s", uniqueKeyColumnNames[i], order)
314314
} else {
315315
uniqueKeyColumnOrder[i] = fmt.Sprintf("%s %s", uniqueKeyColumnNames[i], order)

go/sql/types.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ const (
1818
UnknownColumnType ColumnType = iota
1919
TimestampColumnType = iota
2020
DateTimeColumnType = iota
21-
EnumColumnValue = iota
21+
EnumColumnType = iota
22+
MediumIntColumnType = iota
2223
)
2324

25+
const maxMediumintUnsigned int32 = 16777215
26+
2427
type TimezoneConvertion struct {
2528
ToTimezone string
2629
}
@@ -50,6 +53,14 @@ func (this *Column) convertArg(arg interface{}) interface{} {
5053
return uint16(i)
5154
}
5255
if i, ok := arg.(int32); ok {
56+
if this.Type == MediumIntColumnType {
57+
// problem with mediumint is that it's a 3-byte type. There is no compatible golang type to match that.
58+
// So to convert from negative to positive we'd need to convert the value manually
59+
if i >= 0 {
60+
return i
61+
}
62+
return uint32(maxMediumintUnsigned + i + 1)
63+
}
5364
return uint32(i)
5465
}
5566
if i, ok := arg.(int64); ok {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
drop table if exists gh_ost_test;
2+
create table gh_ost_test (
3+
id bigint(20) NOT NULL AUTO_INCREMENT,
4+
column1 int(11) NOT NULL,
5+
column2 smallint(5) unsigned NOT NULL,
6+
column3 mediumint(8) unsigned NOT NULL,
7+
column4 tinyint(3) unsigned NOT NULL,
8+
column5 int(11) NOT NULL,
9+
column6 int(11) NOT NULL,
10+
PRIMARY KEY (id),
11+
KEY c12_ix (column1, column2)
12+
) auto_increment=1;
13+
14+
drop event if exists gh_ost_test;
15+
delimiter ;;
16+
create event gh_ost_test
17+
on schedule every 1 second
18+
starts current_timestamp
19+
ends current_timestamp + interval 60 second
20+
on completion not preserve
21+
enable
22+
do
23+
begin
24+
-- mediumint maxvalue: 16777215 (unsigned), 8388607 (signed)
25+
insert into gh_ost_test values (NULL, 13382498, 536, 8388607, 3, 1483892217, 1483892218);
26+
insert into gh_ost_test values (NULL, 13382498, 536, 8388607, 250, 1483892217, 1483892218);
27+
insert into gh_ost_test values (NULL, 13382498, 536, 10000000, 3, 1483892217, 1483892218);
28+
end ;;

0 commit comments

Comments
 (0)