Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#52542
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
YangKeao authored and ti-chi-bot committed May 13, 2024
1 parent 335e834 commit 3781969
Show file tree
Hide file tree
Showing 7 changed files with 8,675 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cmd/explaintest/r/explain_easy.result
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,11 @@ StreamAgg 1.00 root funcs:count(1)->Column#22
│ └─Projection 1.00 root Column#33, Column#34, Column#35, Column#14, Column#15, Column#16
│ └─HashAgg 1.00 root group by:test.test01.region_id, test.test01.show_date, test.test01.stat_date, funcs:firstrow(test.test01.stat_date)->Column#33, funcs:firstrow(test.test01.show_date)->Column#34, funcs:firstrow(test.test01.region_id)->Column#35, funcs:firstrow(test.test01.stat_date)->Column#14, funcs:firstrow(test.test01.show_date)->Column#15, funcs:firstrow(test.test01.region_id)->Column#16, funcs:count(1)->Column#39
│ └─TableReader 0.01 root data:Selection
<<<<<<< HEAD:cmd/explaintest/r/explain_easy.result
│ └─Selection 0.01 cop[tikv] eq(test.test01.period, 1), ge(test.test01.stat_date, 20191202), gt(cast(test.test01.registration_num, bigint(20) BINARY), 0), le(test.test01.stat_date, 20191202)
=======
│ └─Selection 0.01 cop[tikv] eq(explain_easy.test01.period, 1), ge(explain_easy.test01.stat_date, 20191202), gt(cast(explain_easy.test01.registration_num, decimal(20,0) BINARY), 0), le(explain_easy.test01.stat_date, 20191202)
>>>>>>> 09c8f964cc5 (planner: fix the issue that UnionAll didn't handle the range bump case (#52542)):tests/integrationtest/r/explain_easy.result
│ └─TableFullScan 10000.00 cop[tikv] table:test01 keep order:false, stats:pseudo
└─TableReader(Probe) 2.00 root data:TableRangeScan
└─TableRangeScan 2.00 cop[tikv] table:b range: decided by [Column#16], keep order:false, stats:pseudo
Expand Down
695 changes: 695 additions & 0 deletions pkg/planner/core/casetest/dag/testdata/plan_suite_out.json

Large diffs are not rendered by default.

1,903 changes: 1,903 additions & 0 deletions pkg/planner/core/casetest/hint/testdata/integration_suite_out.json

Large diffs are not rendered by default.

3,750 changes: 3,750 additions & 0 deletions pkg/planner/core/casetest/physicalplantest/testdata/plan_suite_out.json

Large diffs are not rendered by default.

2,315 changes: 2,315 additions & 0 deletions pkg/planner/core/integration_test.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1692,7 +1692,7 @@ func unionJoinFieldType(a, b *types.FieldType) *types.FieldType {
} else if b.GetType() == mysql.TypeNull {
return a
}
resultTp := types.NewFieldType(types.MergeFieldType(a.GetType(), b.GetType()))
resultTp := types.AggFieldType([]*types.FieldType{a, b})
// This logic will be intelligible when it is associated with the buildProjection4Union logic.
if resultTp.GetType() == mysql.TypeNewDecimal {
// The decimal result type will be unsigned only when all the decimals to be united are unsigned.
Expand Down
10 changes: 7 additions & 3 deletions types/field_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func AggFieldType(tps []*FieldType) *FieldType {
currType = *t
continue
}
mtp := MergeFieldType(currType.GetType(), t.GetType())
mtp := mergeFieldType(currType.GetType(), t.GetType())
isMixedSign = isMixedSign || (mysql.HasUnsignedFlag(currType.GetFlag()) != mysql.HasUnsignedFlag(t.GetFlag()))
currType.SetType(mtp)
currType.SetFlag(mergeTypeFlag(currType.GetFlag(), t.GetFlag()))
Expand Down Expand Up @@ -353,12 +353,16 @@ func DefaultCharsetForType(tp byte) (defaultCharset string, defaultCollation str
return charset.CharsetBin, charset.CollationBin
}

// MergeFieldType merges two MySQL type to a new type.
// mergeFieldType merges two MySQL type to a new type.
// This is used in hybrid field type expression.
// For example "select case c when 1 then 2 when 2 then 'tidb' from t;"
// The result field type of the case expression is the merged type of the two when clause.
// See https://github.com/mysql/mysql-server/blob/8.0/sql/field.cc#L1042
func MergeFieldType(a byte, b byte) byte {
//
// This function doesn't handle the range bump: for example, when the unsigned long is merged with signed long,
// the result should be longlong. However, this function returns long for this case. Please use `AggFieldType`
// function if you need to handle the range bump.
func mergeFieldType(a byte, b byte) byte {
ia := getFieldTypeIndex(a)
ib := getFieldTypeIndex(b)
return fieldTypeMergeRules[ia][ib]
Expand Down

0 comments on commit 3781969

Please sign in to comment.