Skip to content

Commit

Permalink
Merge pull request #9140 from planetscale/hash-join
Browse files Browse the repository at this point in the history
gen4: Add hash join primitive and planning
  • Loading branch information
systay authored Nov 22, 2021
2 parents 856aef4 + ccee93d commit ae58d49
Show file tree
Hide file tree
Showing 58 changed files with 2,526 additions and 458 deletions.
3 changes: 3 additions & 0 deletions go/hack/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ func roundupsize(size uintptr) uintptr
func RuntimeAllocSize(size int64) int64 {
return int64(roundupsize(uintptr(size)))
}

//go:linkname ParseFloatPrefix strconv.parseFloatPrefix
func ParseFloatPrefix(s string, bitSize int) (float64, int, error)
6 changes: 3 additions & 3 deletions go/mysql/collations/8bit.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c *Collation_8bit_bin) WeightString(dst, src []byte, numCodepoints int) []
return weightStringPadingSimple(' ', dst, numCodepoints-copyCodepoints, padToMax)
}

func (c *Collation_8bit_bin) Hash(src []byte, numCodepoints int) uintptr {
func (c *Collation_8bit_bin) Hash(src []byte, numCodepoints int) HashCode {
hash := 0x8b8b0000 | uintptr(c.id)
if numCodepoints == 0 {
return memhash(src, hash)
Expand Down Expand Up @@ -164,7 +164,7 @@ func (c *Collation_8bit_simple_ci) WeightString(dst, src []byte, numCodepoints i
return weightStringPadingSimple(' ', dst, numCodepoints-copyCodepoints, padToMax)
}

func (c *Collation_8bit_simple_ci) Hash(src []byte, numCodepoints int) uintptr {
func (c *Collation_8bit_simple_ci) Hash(src []byte, numCodepoints int) HashCode {
sortOrder := c.sort

var tocopy = len(src)
Expand Down Expand Up @@ -251,7 +251,7 @@ func (c *Collation_binary) WeightString(dst, src []byte, numCodepoints int) []by
return dst
}

func (c *Collation_binary) Hash(src []byte, numCodepoints int) uintptr {
func (c *Collation_binary) Hash(src []byte, numCodepoints int) HashCode {
if numCodepoints > 0 {
src = src[:numCodepoints]
}
Expand Down
4 changes: 3 additions & 1 deletion go/mysql/collations/collation.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type Collation interface {
// the hash will interpret the source string as if it were stored in a `CHAR(n)` column. If the value of
// numCodepoints is 0, this is equivalent to setting `numCodepoints = RuneCount(src)`.
// For collations with NO PAD, the numCodepoint argument is ignored.
Hash(src []byte, numCodepoints int) uintptr
Hash(src []byte, numCodepoints int) HashCode

// Charset returns the Charset with which this collation is encoded
Charset() charset.Charset
Expand All @@ -128,6 +128,8 @@ type Collation interface {
IsBinary() bool
}

type HashCode = uintptr

const PadToMax = math.MaxInt32

func minInt(i1, i2 int) int {
Expand Down
2 changes: 1 addition & 1 deletion go/mysql/collations/multibyte.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (c *Collation_multibyte) WeightString(dst, src []byte, numCodepoints int) [
return dst
}

func (c *Collation_multibyte) Hash(src []byte, numCodepoints int) uintptr {
func (c *Collation_multibyte) Hash(src []byte, numCodepoints int) HashCode {
cs := c.charset
sortOrder := c.sort

Expand Down
2 changes: 1 addition & 1 deletion go/mysql/collations/remote/collation.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (c *Collation) WeightString(dst, src []byte, numCodepoints int) []byte {
return dst
}

func (c *Collation) Hash(_ []byte, _ int) uintptr {
func (c *Collation) Hash(_ []byte, _ int) collations.HashCode {
panic("unsupported: Hash for remote collations")
}

Expand Down
6 changes: 3 additions & 3 deletions go/mysql/collations/uca.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ performPadding:
return dst
}

func (c *Collation_utf8mb4_uca_0900) Hash(src []byte, _ int) uintptr {
func (c *Collation_utf8mb4_uca_0900) Hash(src []byte, _ int) HashCode {
var hash = uintptr(c.id)

it := c.uca.Iterator(src)
Expand Down Expand Up @@ -234,7 +234,7 @@ func (c *Collation_utf8mb4_0900_bin) WeightString(dst, src []byte, numCodepoints
return dst
}

func (c *Collation_utf8mb4_0900_bin) Hash(src []byte, _ int) uintptr {
func (c *Collation_utf8mb4_0900_bin) Hash(src []byte, _ int) HashCode {
return memhash(src, 0xb900b900)
}

Expand Down Expand Up @@ -340,7 +340,7 @@ func (c *Collation_uca_legacy) WeightString(dst, src []byte, numCodepoints int)
return dst
}

func (c *Collation_uca_legacy) Hash(src []byte, numCodepoints int) uintptr {
func (c *Collation_uca_legacy) Hash(src []byte, numCodepoints int) HashCode {
it := c.uca.Iterator(src)
defer it.Done()

Expand Down
4 changes: 2 additions & 2 deletions go/mysql/collations/unicode.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (c *Collation_unicode_general_ci) WeightString(dst, src []byte, numCodepoin
return dst
}

func (c *Collation_unicode_general_ci) Hash(src []byte, numCodepoints int) uintptr {
func (c *Collation_unicode_general_ci) Hash(src []byte, numCodepoints int) HashCode {
unicaseInfo := c.unicase
cs := c.charset

Expand Down Expand Up @@ -278,7 +278,7 @@ func (c *Collation_unicode_bin) weightStringUnicode(dst, src []byte, numCodepoin
return dst
}

func (c *Collation_unicode_bin) Hash(src []byte, numCodepoints int) uintptr {
func (c *Collation_unicode_bin) Hash(src []byte, numCodepoints int) HashCode {
if c.charset.SupportsSupplementaryChars() {
return c.hashUnicode(src, numCodepoints)
}
Expand Down
5 changes: 5 additions & 0 deletions go/sqltypes/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ func IsDate(t querypb.Type) bool {
return t == Datetime || t == Date || t == Timestamp || t == Time
}

// IsNull returns true if the type is NULL type
func IsNull(t querypb.Type) bool {
return t == Null
}

// Vitess data types. These are idiomatically
// named synonyms for the querypb.Type values.
// Although these constants are interchangeable,
Expand Down
7 changes: 7 additions & 0 deletions go/sqltypes/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ func (v Value) Raw() []byte {
return v.val
}

// RawStr returns the internal representation of the value as a string instead
// of a byte slice. This is equivalent to calling `string(v.Raw())` but does
// not allocate.
func (v Value) RawStr() string {
return hack.String(v.val)
}

// ToBytes returns the value as MySQL would return it as []byte.
// In contrast, Raw returns the internal representation of the Value, which may not
// match MySQL's representation for newer types.
Expand Down
10 changes: 5 additions & 5 deletions go/test/endtoend/vtgate/gen4/column_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"context"
"testing"

"vitess.io/vitess/go/test/endtoend/vtgate/utils"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand All @@ -35,12 +37,10 @@ func TestColumnNames(t *testing.T) {
require.NoError(t, err)
defer conn.Close()

_, err = exec(t, conn, "create table uks.t2(id bigint,phone bigint,msg varchar(100),primary key(id)) Engine=InnoDB")
require.NoError(t, err)
defer exec(t, conn, "drop table uks.t2")
utils.Exec(t, conn, "create table uks.t2(id bigint,phone bigint,msg varchar(100),primary key(id)) Engine=InnoDB")
defer utils.Exec(t, conn, "drop table uks.t2")

qr, err := exec(t, conn, "SELECT t1.id as t1id, t2.id as t2id, t2.phone as t2phn FROM ks.t1 cross join uks.t2 where t1.id = t2.id ORDER BY t2.phone")
require.NoError(t, err)
qr := utils.Exec(t, conn, "SELECT t1.id as t1id, t2.id as t2id, t2.phone as t2phn FROM ks.t1 cross join uks.t2 where t1.id = t2.id ORDER BY t2.phone")

assert.Equal(t, 3, len(qr.Fields))
assert.Equal(t, "t1id", qr.Fields[0].Name)
Expand Down
Loading

0 comments on commit ae58d49

Please sign in to comment.