Skip to content

Commit

Permalink
backport Change internal vindex type recommendation for integrals to …
Browse files Browse the repository at this point in the history
…xxhash vitessio#13956

Signed-off-by: Vilius Okockis <[email protected]>
  • Loading branch information
DeathBorn committed Sep 25, 2024
1 parent ab7605b commit ce26045
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 116 deletions.
5 changes: 3 additions & 2 deletions go/vt/vtgate/vindexes/vschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,12 @@ func LoadFormalKeyspace(filename string) (*vschemapb.Keyspace, error) {
return formal, nil
}

// ChooseVindexForType chooses the most appropriate vindex for the give type.
// ChooseVindexForType chooses the most appropriate vindex type for
// the given SQL data type.
func ChooseVindexForType(typ querypb.Type) (string, error) {
switch {
case sqltypes.IsIntegral(typ):
return "hash", nil
return "xxhash", nil
case sqltypes.IsText(typ):
return "unicode_loose_md5", nil
case sqltypes.IsBinary(typ):
Expand Down
35 changes: 20 additions & 15 deletions go/vt/vtgate/vindexes/vschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,37 +821,37 @@ func TestChooseVindexForType(t *testing.T) {
out: "",
}, {
in: sqltypes.Int8,
out: "hash",
out: "xxhash",
}, {
in: sqltypes.Uint8,
out: "hash",
out: "xxhash",
}, {
in: sqltypes.Int16,
out: "hash",
out: "xxhash",
}, {
in: sqltypes.Uint16,
out: "hash",
out: "xxhash",
}, {
in: sqltypes.Int24,
out: "hash",
out: "xxhash",
}, {
in: sqltypes.Uint24,
out: "hash",
out: "xxhash",
}, {
in: sqltypes.Int32,
out: "hash",
out: "xxhash",
}, {
in: sqltypes.Uint32,
out: "hash",
out: "xxhash",
}, {
in: sqltypes.Int64,
out: "hash",
out: "xxhash",
}, {
in: sqltypes.Uint64,
out: "hash",
out: "xxhash",
}, {
in: sqltypes.Float32,
out: "hash",
out: "",
}, {
in: sqltypes.Float64,
out: "",
Expand All @@ -869,7 +869,7 @@ func TestChooseVindexForType(t *testing.T) {
out: "",
}, {
in: sqltypes.Year,
out: "hash",
out: "xxhash",
}, {
in: sqltypes.Decimal,
out: "",
Expand Down Expand Up @@ -913,11 +913,16 @@ func TestChooseVindexForType(t *testing.T) {

for _, tcase := range testcases {
out, err := ChooseVindexForType(tcase.in)
if out == "" {
assert.Error(t, err, tcase.in)
// If no type is returned then we do not recommend the column be
// used for a vindex. If the test case provides an empty output
// value then we expect an error.
if tcase.out == "" {
assert.Error(t, err, "unexpectedly got a recommended vindex type of %s for input column type %v",
out, tcase.in)
continue
}
assert.Equal(t, out, tcase.out, tcase.in)
assert.Equal(t, out, tcase.out, "expected a recommended vindex type of %s for input column type %v but got %s",
tcase.out, tcase.in, out)
}
}

Expand Down
Loading

0 comments on commit ce26045

Please sign in to comment.