Skip to content

Commit

Permalink
planner: add hash64 and equal for maxOneRow and fix some bugs. (#57259)
Browse files Browse the repository at this point in the history
ref #51664
  • Loading branch information
AilinKid authored Nov 11, 2024
1 parent 1b49096 commit b5cf2c3
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 24 deletions.
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)
}

// 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.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ go_test(
"logical_mem_table_predicate_extractor_test.go",
],
flaky = True,
shard_count = 18,
shard_count = 19,
deps = [
"//pkg/domain",
"//pkg/expression",
Expand Down
Loading

0 comments on commit b5cf2c3

Please sign in to comment.