Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
Signed-off-by: AilinKid <[email protected]>
  • Loading branch information
AilinKid committed Nov 12, 2024
1 parent 94aaee3 commit 866c08a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main
import (
"bytes"
"fmt"
"github.com/pingcap/tidb/pkg/parser/types"
"go/format"
"log"
"os"
Expand Down Expand Up @@ -49,7 +50,14 @@ func GenHash64Equals4LogicalOps() ([]byte, error) {
return c.format()
}

// IHashEquals is the interface for hash64 and equals inside parser pkg.
type IHashEquals interface {
Hash64(h types.IHasher)
Equals(other any) bool
}

var hashEqualsType = reflect.TypeOf((*base.HashEquals)(nil)).Elem()
var iHashEqualsType = reflect.TypeOf((*IHashEquals)(nil)).Elem()

func genHash64EqualsForLogicalOps(x any) ([]byte, error) {
c := new(cc)
Expand Down Expand Up @@ -152,7 +160,8 @@ func (c *cc) EqualsElement(fType reflect.Type, lhs, rhs string, i string) {
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64:
c.write("if %v != %v {return false}", lhs, rhs)
default:
if fType.Implements(hashEqualsType) || reflect.PtrTo(fType).Implements(hashEqualsType) {
if fType.Implements(hashEqualsType) || fType.Implements(iHashEqualsType) ||
reflect.PtrTo(fType).Implements(hashEqualsType) || reflect.PtrTo(fType).Implements(iHashEqualsType) {
if fType.Kind() == reflect.Struct {
rhs = "&" + rhs
}
Expand Down Expand Up @@ -186,7 +195,8 @@ func (c *cc) Hash64Element(fType reflect.Type, callName string) {
case reflect.Float32, reflect.Float64:
c.write("h.HashFloat64(float64(%v))", callName)
default:
if fType.Implements(hashEqualsType) || reflect.PtrTo(fType).Implements(hashEqualsType) {
if fType.Implements(hashEqualsType) || fType.Implements(iHashEqualsType) ||
reflect.PtrTo(fType).Implements(hashEqualsType) || reflect.PtrTo(fType).Implements(iHashEqualsType) {
c.write("%v.Hash64(h)", callName)
} else {
panic("doesn't support element type" + fType.Kind().String())
Expand Down

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

2 changes: 1 addition & 1 deletion pkg/planner/core/operator/logicalop/logical_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type DataSource struct {
Columns []*model.ColumnInfo
DBName pmodel.CIStr

TableAsName *pmodel.CIStr
TableAsName *pmodel.CIStr `hash64-equals:"true"`
// IndexMergeHints are the hint for indexmerge.
IndexMergeHints []h.HintedIndex
// PushedDownConds are the conditions that will be pushed down to coprocessor.
Expand Down

0 comments on commit 866c08a

Please sign in to comment.