Skip to content
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: fix type infer for tidb's builtin compare(least and greatest) #21150

Merged
merged 32 commits into from
Dec 22, 2020

Conversation

iosmanthus
Copy link
Contributor

@iosmanthus iosmanthus commented Nov 19, 2020

Signed-off-by: iosmanthus myosmanthustree@gmail.com

What problem does this PR solve?

Issue Number:
close #17994
close #9765

Problem Summary:

What is changed and how it works?

What's Changed:
This pull request migrates some MySQL type merge rules to make TiDB's type infer rules more MySQL compatible.

How it Works:
This pull request port https://github.com/mysql/mysql-server/blob/ee4455a33b10f1b1886044322e4893f587b319ed/sql%2Fitem_func.cc#L3470 to infer the result type of least/greatest

Related changes

  • PR to update pingcap/docs/pingcap/docs-cn:
  • Need to cherry-pick to the release branch

Check List

Tests

  • Unit test
  • Integration test
  • No code

Side effects

  • Performance regression
    • Consumes more CPU
    • Consumes more MEM
  • Breaking backward compatibility

Release note

  • expression: fix type infer for TiDB's builtin compare(least and greatest)

Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
@iosmanthus iosmanthus requested review from a team as code owners November 19, 2020 12:57
@iosmanthus iosmanthus requested review from qw4990 and XuHuaiyu and removed request for a team November 19, 2020 12:57
Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
@ichn-hu ichn-hu mentioned this pull request Nov 19, 2020
@@ -1258,6 +1262,49 @@ var fieldTypeMergeRules = [fieldTypeNum][fieldTypeNum]byte{
},
}

const (
InvalidResult byte = 0 /** not valid for UDFs */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you need to define a new type for these constants?

StringResult byte = 1 /** char * */
RealResult byte = 2 /** double */
IntResult byte = 3 /** long long */
RowResult byte = 4 /** not valid for UDFs */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused?

RealResult byte = 2 /** double */
IntResult byte = 3 /** long long */
RowResult byte = 4 /** not valid for UDFs */
DecimalResult byte = 5 /** char *, to be converted to/from a decimal */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no char * in TiDB?

StringResult, StringResult,
// mysql.TypeBit mysql.TypeInvalid
IntResult, InvalidResult,
// Unused entries: <17>-<242>
Copy link
Member

@breezewish breezewish Nov 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In previous definitions, the matrix order is TypeBit, <16>-<244>, TypeJSON, ...

In this implementation, the order is TypeBit, TypeInvalid, <17>-<242>, TypeBool, TypeJSON

Array elements are no longer aligned. Will there be problems?

Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
@breezewish
Copy link
Member

/cc @lzmhhh123

@lzmhhh123 lzmhhh123 linked an issue Nov 24, 2020 that may be closed by this pull request
@lzmhhh123
Copy link
Contributor

/reward 900

@ti-challenge-bot
Copy link

This PR's linked issue is not picked.

@breezewish
Copy link
Member

/run-all-tests

Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
@SunRunAway SunRunAway added the type/bugfix This PR fixes a bug. label Nov 25, 2020
@SunRunAway
Copy link
Contributor

@iosmanthus Should it be cherry-picked into release-3.0 and release-4.0?

Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
@iosmanthus
Copy link
Contributor Author

@lzmhhh123 @breeswish PTAL

Signed-off-by: iosmanthus <myosmanthustree@gmail.com>

var temporalItem *types.FieldType
aggType.EvalType()
if types.ResultMergeType(aggType.Tp) == types.ETString {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can check whether the ETType == ETDatetime || ETType == ETString || ... instead of using ResultMergeType here.

Signed-off-by: iosmanthus <myosmanthustree@gmail.com>
XuHuaiyu
XuHuaiyu previously approved these changes Dec 21, 2020
Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-srebot ti-srebot removed the status/LGT1 Indicates that a PR has LGTM 1. label Dec 21, 2020
ti-srebot
ti-srebot previously approved these changes Dec 21, 2020
@ti-srebot ti-srebot added the status/LGT2 Indicates that a PR has LGTM 2. label Dec 21, 2020
@iosmanthus iosmanthus dismissed stale reviews from ti-srebot and XuHuaiyu via 0432977 December 21, 2020 15:27
@XuHuaiyu
Copy link
Contributor

/run-all-tests tidb-test=pr/1137

@XuHuaiyu
Copy link
Contributor

/run-unit-test

@lzmhhh123
Copy link
Contributor

/merge

@ti-srebot ti-srebot added the status/can-merge Indicates a PR has been approved by a committer. label Dec 22, 2020
@ti-srebot
Copy link
Contributor

/run-all-tests

@ti-srebot ti-srebot merged commit dd0dc46 into pingcap:master Dec 22, 2020
ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Dec 22, 2020
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-4.0 in PR #21924

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/expression status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. type/bugfix This PR fixes a bug.
Projects
None yet
8 participants