Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: add hash64 and equal for maxOneRow and fix some bugs. #57259

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/expression/aggregation/descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (a *AggFuncDesc) Equals(other any) bool {
return false
}
}
return a.baseFuncDesc.Equals(otherAgg.baseFuncDesc)
return a.baseFuncDesc.Equals(&otherAgg.baseFuncDesc)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current Equals implementation only receive pointer

}

// StringWithCtx returns the string representation within given ctx.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import (
// If a field is tagged with `hash64-equals`, then it will be computed in hash64 and equals func.
// If a field is not tagged, then it will be skipped.
func GenHash64Equals4LogicalOps() ([]byte, error) {
var structures = []any{logicalop.LogicalJoin{}, logicalop.LogicalAggregation{}, logicalop.LogicalApply{}, logicalop.LogicalExpand{}, logicalop.LogicalLimit{}}
var structures = []any{logicalop.LogicalJoin{}, logicalop.LogicalAggregation{}, logicalop.LogicalApply{},
logicalop.LogicalExpand{}, logicalop.LogicalLimit{}, logicalop.LogicalMaxOneRow{}}
c := new(cc)
c.write(codeGenHash64EqualsPrefix)
for _, s := range structures {
Expand Down Expand Up @@ -80,15 +81,20 @@ func genHash64EqualsForLogicalOps(x any) ([]byte, error) {
c.write("if other == nil { return false }")
c.write("op2, ok := other.(*%v)", vType.Name())
c.write("if !ok { return false }")
hasValidField := false
for i := 0; i < vType.NumField(); i++ {
f := vType.Field(i)
if !isHash64EqualsField(f) {
continue
}
hasValidField = true
leftCallName := "op." + vType.Field(i).Name
rightCallName := "op2." + vType.Field(i).Name
c.EqualsElement(f.Type, leftCallName, rightCallName, "i")
}
if !hasValidField {
c.write("_ = op2")
}
c.write("return true")
c.write("}")
return c.format()
Expand All @@ -106,6 +112,8 @@ func logicalOpName2PlanCodecString(name string) string {
return "plancodec.TypeExpand"
case "LogicalLimit":
return "plancodec.TypeLimit"
case "LogicalMaxOneRow":
return "plancodec.TypeMaxOneRow"
default:
return ""
}
Expand All @@ -119,7 +127,7 @@ func isHash64EqualsField(fType reflect.StructField) bool {
func (c *cc) EqualsElement(fType reflect.Type, lhs, rhs string, i string) {
switch fType.Kind() {
case reflect.Slice:
c.write("if len(%v) != len(%v) { return false }", lhs, rhs)
c.write("if (%v == nil && %v != nil) || (%v != nil && %v == nil) || len(%v) != len(%v) { return false }", lhs, rhs, lhs, rhs, lhs, rhs)
itemName := "one"
if strings.HasPrefix(lhs, "one") {
itemName = lhs + "e"
Expand Down
54 changes: 36 additions & 18 deletions pkg/planner/core/operator/logicalop/hash64_equals_generated.go

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

Loading