pingcap / pingcap/tidb

hash64 doesn't has a cache inside the related element

Open
#57,884 0 comments 0 reactions 1 assignee Claimed by @AilinKid View on GitHub
planner/cascades sig/planner type/enhancement
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Enhancement
```
// Hash64 is the interface for hashcode.
// It is used to calculate the lossy digest of an object to return uint64
// rather than compacted bytes from cascaded operators bottom-up.
type Hash64 interface {
// Hash64 returns the uint64 digest of an object.
Hash64(h Hasher)
}

// Equals is the interface for equality check.
// When we need to compare two objects when countering hash conflicts, we can
// use this interface to check whether they are equal.
type Equals interface {
// Equals checks whether two base objects are equal.
Equals(any) bool
}

// HashEquals is the interface for hash64 and equality check.
type HashEquals interface {
Hash64
Equals
}
```

currently hash64 pass the hasher into every element inside to accumulate the hash64's incremental, while it doesn't compute the result based on each child's independent hash64 value, which also means the top caller can only cache itself hash64, for it's child element, the cache is meaningless.
```
struct A {
a int
element1
element2
}

func (a *A) hash64(h hasher) {
h.hashInt(a)
element1.hash64(h)
element2.hash64(h)
}
```
Since hash64 is only used in memo phase, only GroupExpression level's cache is adequate, and we don't whether the basic element inside is changed or not, change the hash algorithm to hash64(int, element1_hash64, element2_hash64) will introduce every UIn64 field for every element related downward and maintaining them is also a burden.
![Image](https://github.com/user-attachments/assets/72a5a514-f2d2-4fba-88c3-0450659d1db8)

when a GroupExpression is generated, the logical operator inside need to compute the hash64 from the each element inside bottom-up, while for GroupExpression's child, group id is not a burden for counting them inside.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.