-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
expression: add simple expression semantic equal check logic #43558
Conversation
Signed-off-by: AilinKid <314806019@qq.com>
[REVIEW NOTIFICATION] This pull request has been approved by:
To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Signed-off-by: AilinKid <314806019@qq.com>
sc := ctx.GetSessionVars().StmtCtx | ||
sc.CanonicalHashCode.Store(true) | ||
defer sc.CanonicalHashCode.Store(false) | ||
return bytes.Equal(expr1.HashCode(sc), expr2.HashCode(sc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(*ScalarFunction).HashCode
is not a pure function and has the side effect(i.e., if len(sf.hashcode) > 0
, then we don't need to recalculate it). Is it ok to expose the hash code calculated under CanonicalHashCode
mode to outside?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
Addressed.
expression/scalar_function.go
Outdated
if !ok { | ||
// use the origin arg hash code. | ||
for _, argCode := range argsHashCode { | ||
sf.hashcode = append(sf.hashcode, argCode...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to encode the not op?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope:
Expression1: not(a<b)
Expression2: a>=b
Expression1 and Expression2 should have the same hashcode, we try to disintegrate the NOT into a mathematical operation convertion.
Signed-off-by: AilinKid <314806019@qq.com>
/merge |
This pull request has been accepted and is ready to merge. Commit hash: ecae432
|
/retest |
What problem does this PR solve?
Issue Number: close #43572
Problem Summary:
What is changed and how it works?
In TiDB Expression tree, sometimes we may need judge whether two expression tree are semantic equal,
this PR adds the simple check logic ported from SparkSQL.
Check List
Tests
Side effects
Documentation
Release note
Please refer to Release Notes Language Style Guide to write a quality release note.