Skip to content

Commit

Permalink
Introduce type and use pointer to reduce size
Browse files Browse the repository at this point in the history
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
  • Loading branch information
dbussink committed Apr 23, 2024
1 parent b0521ad commit 595ec8f
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 129 deletions.
2 changes: 1 addition & 1 deletion go/vt/vtgate/engine/aggregations.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ type aggregatorDistinct struct {
last sqltypes.Value
coll collations.ID
collationEnv *collations.Environment
values []string
values *evalengine.EnumSetValues
}

func (a *aggregatorDistinct) shouldReturn(row []sqltypes.Value) (bool, error) {
Expand Down
25 changes: 13 additions & 12 deletions go/vt/vtgate/engine/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions go/vt/vtgate/engine/hash_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type (
CollationEnv *collations.Environment

// Values for enum and set types
Values []string
Values *evalengine.EnumSetValues
}

hashJoinProbeTable struct {
Expand All @@ -81,7 +81,7 @@ type (
cols []int
hasher vthash.Hasher
sqlmode evalengine.SQLMode
values []string
values *evalengine.EnumSetValues
}

probeTableEntry struct {
Expand Down Expand Up @@ -264,7 +264,7 @@ func (hj *HashJoin) description() PrimitiveDescription {
}
}

func newHashJoinProbeTable(coll collations.ID, typ querypb.Type, lhsKey, rhsKey int, cols []int, values []string) *hashJoinProbeTable {
func newHashJoinProbeTable(coll collations.ID, typ querypb.Type, lhsKey, rhsKey int, cols []int, values *evalengine.EnumSetValues) *hashJoinProbeTable {
return &hashJoinProbeTable{
innerMap: map[vthash.Hash]*probeTableEntry{},
coll: coll,
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/evalengine/api_aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ type aggregationMinMax struct {
current sqltypes.Value
collation collations.ID
collationEnv *collations.Environment
values []string
values *EnumSetValues
}

func (a *aggregationMinMax) minmax(value sqltypes.Value, max bool) (err error) {
Expand Down Expand Up @@ -485,7 +485,7 @@ func (a *aggregationMinMax) Reset() {
a.current = sqltypes.NULL
}

func NewAggregationMinMax(typ sqltypes.Type, collationEnv *collations.Environment, collation collations.ID, values []string) MinMax {
func NewAggregationMinMax(typ sqltypes.Type, collationEnv *collations.Environment, collation collations.ID, values *EnumSetValues) MinMax {
switch {
case sqltypes.IsSigned(typ):
return &aggregationInt{t: typ}
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/evalengine/api_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (err UnsupportedCollationError) Error() string {
// UnsupportedCollationHashError is returned when we try to get the hash value and are missing the collation to use
var UnsupportedCollationHashError = vterrors.Errorf(vtrpcpb.Code_INTERNAL, "text type with an unknown/unsupported collation cannot be hashed")

func compare(v1, v2 sqltypes.Value, collationEnv *collations.Environment, collationID collations.ID, values []string) (int, error) {
func compare(v1, v2 sqltypes.Value, collationEnv *collations.Environment, collationID collations.ID, values *EnumSetValues) (int, error) {
v1t := v1.Type()

// We have a fast path here for the case where both values are
Expand Down Expand Up @@ -147,7 +147,7 @@ func compare(v1, v2 sqltypes.Value, collationEnv *collations.Environment, collat
// numeric, then a numeric comparison is performed after
// necessary conversions. If none are numeric, then it's
// a simple binary comparison. Uncomparable values return an error.
func NullsafeCompare(v1, v2 sqltypes.Value, collationEnv *collations.Environment, collationID collations.ID, values []string) (int, error) {
func NullsafeCompare(v1, v2 sqltypes.Value, collationEnv *collations.Environment, collationID collations.ID, values *EnumSetValues) (int, error) {
// Based on the categorization defined for the types,
// we're going to allow comparison of the following:
// Null, isNumber, IsBinary. This will exclude IsQuoted
Expand Down
16 changes: 7 additions & 9 deletions go/vt/vtgate/evalengine/api_compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ import (
"github.com/stretchr/testify/require"

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/sqltypes"
querypb "vitess.io/vitess/go/vt/proto/query"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vtenv"
"vitess.io/vitess/go/vt/vterrors"

"vitess.io/vitess/go/sqltypes"

querypb "vitess.io/vitess/go/vt/proto/query"
)

type testCase struct {
Expand Down Expand Up @@ -1114,7 +1112,7 @@ func TestNullsafeCompare(t *testing.T) {
v1, v2 sqltypes.Value
out int
err error
values []string
values *EnumSetValues
}{
{
v1: NULL,
Expand Down Expand Up @@ -1145,7 +1143,7 @@ func TestNullsafeCompare(t *testing.T) {
v1: TestValue(sqltypes.Enum, "foo"),
v2: TestValue(sqltypes.Enum, "bar"),
out: -1,
values: []string{"'foo'", "'bar'"},
values: &EnumSetValues{"'foo'", "'bar'"},
},
{
v1: TestValue(sqltypes.Enum, "foo"),
Expand All @@ -1156,7 +1154,7 @@ func TestNullsafeCompare(t *testing.T) {
v1: TestValue(sqltypes.Enum, "foo"),
v2: TestValue(sqltypes.VarChar, "bar"),
out: 1,
values: []string{"'foo'", "'bar'"},
values: &EnumSetValues{"'foo'", "'bar'"},
},
{
v1: TestValue(sqltypes.VarChar, "foo"),
Expand All @@ -1167,7 +1165,7 @@ func TestNullsafeCompare(t *testing.T) {
v1: TestValue(sqltypes.Set, "bar"),
v2: TestValue(sqltypes.Set, "foo,bar"),
out: -1,
values: []string{"'foo'", "'bar'"},
values: &EnumSetValues{"'foo'", "'bar'"},
},
{
v1: TestValue(sqltypes.Set, "bar"),
Expand All @@ -1178,7 +1176,7 @@ func TestNullsafeCompare(t *testing.T) {
v1: TestValue(sqltypes.VarChar, "bar"),
v2: TestValue(sqltypes.Set, "foo,bar"),
out: -1,
values: []string{"'foo'", "'bar'"},
values: &EnumSetValues{"'foo'", "'bar'"},
},
{
v1: TestValue(sqltypes.Set, "bar"),
Expand Down
6 changes: 3 additions & 3 deletions go/vt/vtgate/evalengine/api_hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type HashCode = uint64

// NullsafeHashcode returns an int64 hashcode that is guaranteed to be the same
// for two values that are considered equal by `NullsafeCompare`.
func NullsafeHashcode(v sqltypes.Value, collation collations.ID, coerceType sqltypes.Type, sqlmode SQLMode, values []string) (HashCode, error) {
func NullsafeHashcode(v sqltypes.Value, collation collations.ID, coerceType sqltypes.Type, sqlmode SQLMode, values *EnumSetValues) (HashCode, error) {
e, err := valueToEvalCast(v, coerceType, collation, values, sqlmode)
if err != nil {
return 0, err
Expand Down Expand Up @@ -75,7 +75,7 @@ var ErrHashCoercionIsNotExact = vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "
// for two values that are considered equal by `NullsafeCompare`.
// This can be used to avoid having to do comparison checks after a hash,
// since we consider the 128 bits of entropy enough to guarantee uniqueness.
func NullsafeHashcode128(hash *vthash.Hasher, v sqltypes.Value, collation collations.ID, coerceTo sqltypes.Type, sqlmode SQLMode, values []string) error {
func NullsafeHashcode128(hash *vthash.Hasher, v sqltypes.Value, collation collations.ID, coerceTo sqltypes.Type, sqlmode SQLMode, values *EnumSetValues) error {
switch {
case v.IsNull(), sqltypes.IsNull(coerceTo):
hash.Write16(hashPrefixNil)
Expand Down Expand Up @@ -233,7 +233,7 @@ func NullsafeHashcode128(hash *vthash.Hasher, v sqltypes.Value, collation collat
return nil
}

func nullsafeHashcode128Default(hash *vthash.Hasher, v sqltypes.Value, collation collations.ID, coerceTo sqltypes.Type, sqlmode SQLMode, values []string) error {
func nullsafeHashcode128Default(hash *vthash.Hasher, v sqltypes.Value, collation collations.ID, coerceTo sqltypes.Type, sqlmode SQLMode, values *EnumSetValues) error {
// Slow path to handle all other types. This uses the generic
// logic for value casting to ensure we match MySQL here.
e, err := valueToEvalCast(v, coerceTo, collation, values, sqlmode)
Expand Down
8 changes: 3 additions & 5 deletions go/vt/vtgate/evalengine/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package evalengine

import (
"slices"

"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/mysql/datetime"
"vitess.io/vitess/go/mysql/decimal"
Expand Down Expand Up @@ -67,7 +65,7 @@ func (a *Arena) newEvalDecimal(dec decimal.Decimal, m, d int32) *evalDecimal {
return a.newEvalDecimalWithPrec(dec.Clamp(m-d, d), d)
}

func (a *Arena) newEvalEnum(raw []byte, values []string) *evalEnum {
func (a *Arena) newEvalEnum(raw []byte, values *EnumSetValues) *evalEnum {
if cap(a.aEnum) > len(a.aEnum) {
a.aEnum = a.aEnum[:len(a.aEnum)+1]
} else {
Expand All @@ -76,11 +74,11 @@ func (a *Arena) newEvalEnum(raw []byte, values []string) *evalEnum {
val := &a.aEnum[len(a.aInt64)-1]
s := string(raw)
val.string = s
val.value = slices.Index(values, s)
val.value = valueIdx(values, s)
return val
}

func (a *Arena) newEvalSet(raw []byte, values []string) *evalSet {
func (a *Arena) newEvalSet(raw []byte, values *EnumSetValues) *evalSet {
if cap(a.aSet) > len(a.aSet) {
a.aSet = a.aSet[:len(a.aSet)+1]
} else {
Expand Down
39 changes: 21 additions & 18 deletions go/vt/vtgate/evalengine/cached_size.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 595ec8f

Please sign in to comment.