-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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, type: fix AggFieldType error when encouter unsigned and sign type #21062
planner, type: fix AggFieldType error when encouter unsigned and sign type #21062
Conversation
No release note, Please follow https://github.com/pingcap/community/blob/master/contributors/release-note-checker.md |
/run-all-test |
/rebuild |
…cap#9869) add ingegral promotion in AggFieldType
be2fcc3
to
efc9e9f
Compare
@@ -28,17 +28,21 @@ import ( | |||
|
|||
// NewOne stands for a number 1. | |||
func NewOne() *Constant { | |||
retT := types.NewFieldType(mysql.TypeTiny) |
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.
I do not understand why we need to change these 2 funcs
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.
because i make test fail when i modify AggFieldType. The test is https://github.com/pingcap/tidb/blob/master/planner/cascades/transformation_rules_test.go#L389. "SQL": "select count(b), sum(b), avg(b), b, max(b), min(b), bit_and(b), bit_or(b), bit_xor(b) from t group by a having sum(b) >= 0 and count(b) >= 0 order by b",
The reason for fail is that the bit_or will add a cast wrap (cast(b as bigint unsigned binary), the arg is unsigned.
the TransformAggToProj will add ifnull wrap ifnull(cast(b as bigint unsigned binary), expression.NewZero()).
ifnull use AggFieldType infer type to tigger integral promotion.
https://github.com/pingcap/tidb/blob/master/planner/core/rule_aggregation_elimination.go#L124
I think this is a easy way to process. what do you think?
if isMixedSign && IsTypeInteger(currType.Tp) { | ||
bumpRange := false // indicate one of tps bump currType range | ||
for _, t := range tps { | ||
bumpRange = bumpRange || (mysql.HasUnsignedFlag(t.Flag) && (t.Tp == currType.Tp || t.Tp == mysql.TypeBit)) |
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.
Why check mysql.TypeBit
specially
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.
because the TypeBit can't be mergeType and assume it max range bit(64). so it must bump.
I find the all IntegerType
merege mysql.TypeBit
is mysql.TypeVarchar
.
It is inconsistent with mysql 8.0 https://github.com/mysql/mysql-server/blob/8.0/sql/field.cc#L248.
Whether it will be consistent with mysql in the future. if not, No need to consider mysql.TypeBit
here
currType.Tp = mtp | ||
currType.Flag = mergeTypeFlag(currType.Flag, t.Flag) | ||
} | ||
// integral promotion when tps contains signed and unsigned | ||
if isMixedSign && IsTypeInteger(currType.Tp) { | ||
bumpRange := false // indicate one of tps bump currType range |
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.
Does MySQL also bumpRange ?
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.
yes, I refer from here https://github.com/mysql/mysql-server/blob/8.0/sql/item.cc#L557
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.
LGTM
PTAL @lzmhhh123 |
PTAL @ichn-hu |
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.
LGTM
9fbdb62
to
4e5c29e
Compare
/run-all-tests |
64c679b
to
3306832
Compare
/run-all-tests |
3306832
to
4e5c29e
Compare
/run-unit-test |
/run-all-tests |
@lzmhhh123 The tests look not stable. How can I avoid it? |
Which test? |
https://github.com/pingcap/tidb/blob/master/planner/core/physical_plan_test.go#L1647 |
What's the error of the fail. |
The error is the estRows is not equal. now I have no infomation. |
Is this test failed?
|
yes, sometime it is right. |
It has nothing to do with this PR. I'll trigger merge again. |
/merge |
Your auto merge job has been accepted, waiting for:
|
/run-all-tests |
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
cherry pick to release-4.0 in PR #21236 |
What problem does this PR solve?
Issue Number:
close #9869
close #17652
Problem Summary: not process UnsignedFlag in AggFieldType
What is changed and how it works?
What's Changed:
types/field_type.go
How it Works:
add UnsignedFlag check in mergeFlag
add integral promotion when encounter signed and unsigned
Related changes
pingcap/docs
/pingcap/docs-cn
:Check List
Tests
Side effects
Release note