diff --git a/go/vt/tabletserver/query_splitter.go b/go/vt/tabletserver/query_splitter.go index 664a4f1d79..ebeca5449c 100644 --- a/go/vt/tabletserver/query_splitter.go +++ b/go/vt/tabletserver/query_splitter.go @@ -309,20 +309,15 @@ func (qs *QuerySplitter) splitBoundariesFloatColumn(pkMinMax *mproto.QueryResult // TODO(shengzhe): support split based on min, max from the string column. func (qs *QuerySplitter) splitBoundariesStringColumn() ([]sqltypes.Value, error) { - firstRow := int64(0x0) - lastRow := int64(0xFFFFFFFFFFFFFF) - splitRange := lastRow - firstRow + 1 + splitRange := int64(0xFFFFFFFF) + 1 splitSize := splitRange / int64(qs.splitCount) - qs.rowCount = splitSize + //TODO(shengzhe): have a better estimated row count based on table size. + qs.rowCount = int64(splitSize) var boundaries []sqltypes.Value for i := 1; i < qs.splitCount; i++ { - buf := make([]byte, 8) - // encode split point into binaries. - binary.BigEndian.PutUint64(buf, uint64(firstRow+splitSize*int64(i))) - // only converts the lower 4 bytes into hex because the upper 4 bytes are - // always 0x00000000 and mysql does byte comparison from the most significant - // bits. - val, err := sqltypes.BuildValue(buf[4:]) + buf := make([]byte, 4) + binary.BigEndian.PutUint32(buf, uint32(splitSize)*uint32(i)) + val, err := sqltypes.BuildValue(buf) if err != nil { return nil, err } diff --git a/go/vt/tabletserver/query_splitter_test.go b/go/vt/tabletserver/query_splitter_test.go index 353150e5f3..127d5f5068 100644 --- a/go/vt/tabletserver/query_splitter_test.go +++ b/go/vt/tabletserver/query_splitter_test.go @@ -444,26 +444,23 @@ func TestSplitQueryStringColumn(t *testing.T) { } got := []proto.BoundQuery{} for _, split := range splits { - if split.RowCount != 24019198012642645 { - t.Errorf("wrong RowCount, got: %v, want: %v", split.RowCount, 1431655765) - } got = append(got, split.Query) } want := []proto.BoundQuery{ { Sql: "select * from test_table where (count > :count) and (id < :" + endBindVarName + ")", - BindVariables: map[string]interface{}{endBindVarName: hexToByteUInt64(0x55555555)[4:]}, + BindVariables: map[string]interface{}{endBindVarName: hexToByteUInt32(0x55555555)}, }, { Sql: fmt.Sprintf("select * from test_table where (count > :count) and (id >= :%s and id < :%s)", startBindVarName, endBindVarName), BindVariables: map[string]interface{}{ - startBindVarName: hexToByteUInt64(0x55555555)[4:], - endBindVarName: hexToByteUInt64(0xAAAAAAAA)[4:], + startBindVarName: hexToByteUInt32(0x55555555), + endBindVarName: hexToByteUInt32(0xAAAAAAAA), }, }, { Sql: "select * from test_table where (count > :count) and (id >= :" + startBindVarName + ")", - BindVariables: map[string]interface{}{startBindVarName: hexToByteUInt64(0xAAAAAAAA)[4:]}, + BindVariables: map[string]interface{}{startBindVarName: hexToByteUInt32(0xAAAAAAAA)}, }, } if !reflect.DeepEqual(got, want) { @@ -471,8 +468,8 @@ func TestSplitQueryStringColumn(t *testing.T) { } } -func hexToByteUInt64(val uint64) []byte { - buf := make([]byte, 8) - binary.BigEndian.PutUint64(buf, val) +func hexToByteUInt32(val uint32) []byte { + buf := make([]byte, 4) + binary.BigEndian.PutUint32(buf, val) return buf }