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

planner: fix the issue that UnionAll didn't handle the range bump case #52542

Merged
merged 1 commit into from
May 11, 2024

Conversation

YangKeao
Copy link
Member

@YangKeao YangKeao commented Apr 12, 2024

What problem does this PR solve?

Issue Number: close #52472

Problem Summary:

The UnionAll should use types.AggFieldType to aggregate the fieldTypes. This function will handle the bump of range. For example, the aggregate of signed and unsigned long will give signed long long.

What changed and how does it work?

Use types.AggFieldType instead of types.MergeFieldType.

This PR also makes types.MergeFieldType private, as it's easy to make such mistakes.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Fix the issue that the content of the result of `union all` may overflow the type.

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 12, 2024
@YangKeao YangKeao marked this pull request as draft April 12, 2024 06:03
@ti-chi-bot ti-chi-bot bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 12, 2024
@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/needs-triage-completed labels Apr 12, 2024
@YangKeao YangKeao marked this pull request as ready for review April 12, 2024 06:42
@ti-chi-bot ti-chi-bot bot removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/needs-tests-checked labels Apr 12, 2024
Copy link

codecov bot commented Apr 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 77.2709%. Comparing base (0362dc8) to head (c0eb773).
Report is 176 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #52542        +/-   ##
================================================
+ Coverage   72.1924%   77.2709%   +5.0785%     
================================================
  Files          1470       1518        +48     
  Lines        427189     470877     +43688     
================================================
+ Hits         308398     363851     +55453     
+ Misses        99588      87223     -12365     
- Partials      19203      19803       +600     
Flag Coverage Δ
integration 52.6536% <100.0000%> (?)
unit 73.8066% <100.0000%> (+2.7281%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9957% <ø> (ø)
parser ∅ <ø> (∅)
br 52.1073% <ø> (+11.0206%) ⬆️

@ti-chi-bot ti-chi-bot bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 12, 2024
@@ -516,7 +516,7 @@ 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:explain_easy.test01.region_id, explain_easy.test01.show_date, explain_easy.test01.stat_date, funcs:firstrow(explain_easy.test01.stat_date)->Column#33, funcs:firstrow(explain_easy.test01.show_date)->Column#34, funcs:firstrow(explain_easy.test01.region_id)->Column#35, funcs:firstrow(explain_easy.test01.stat_date)->Column#14, funcs:firstrow(explain_easy.test01.show_date)->Column#15, funcs:firstrow(explain_easy.test01.region_id)->Column#16, funcs:count(1)->Column#39
│ └─TableReader 0.01 root data:Selection
│ └─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, bigint(20) BINARY), 0), le(explain_easy.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)
Copy link
Member Author

Choose a reason for hiding this comment

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

It unions integer literal 0 with the unsigned big int. It's expected to produce new decimal. I've checked that this behavior is compatible with MySQL, and the related tests have been added in TestIssue52472

@YangKeao YangKeao force-pushed the fix-52472 branch 2 times, most recently from 2cfca00 to 8853551 Compare April 15, 2024 10:13
" ├─Selection 3323.33 mpp[tiflash] lt(test.t.a, 18), lt(test.t.a, 60)]",
" │ └─TableFullScan 10000.00 mpp[tiflash] table:t pushed down filter:empty, keep order:false, stats:pseudo]",
" └─Selection 1107.78 mpp[tiflash] gt(test.t.b, 1), lt(test.t.a, 60)]",
" └─TableFullScan 10000.00 mpp[tiflash] table:t pushed down filter:empty, keep order:false, stats:pseudo]",
Copy link
Member Author

@YangKeao YangKeao Apr 15, 2024

Choose a reason for hiding this comment

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

It's expected. The original column definition of Union doesn't have NOT NULL flag, which is the reason for the cast above.

The mergeFieldType didn't handle the type flag, but the AggFieldType did. In this PR, both the original column in table and the union column have the NOT NULL flag, so the cast is not needed.

@ti-chi-bot ti-chi-bot bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 15, 2024
@YangKeao
Copy link
Member Author

/retest

Copy link
Member

@time-and-fate time-and-fate left a comment

Choose a reason for hiding this comment

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

LGTM.
But there's more difference between the new and old logic than the bugfix itself. I'm not sure if they are all expected and correct.
I think it's better to have another reviewer more familiar with the types.

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Apr 16, 2024
@YangKeao YangKeao requested a review from xhebox May 11, 2024 05:16
Copy link

ti-chi-bot bot commented May 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: time-and-fate, xhebox

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels May 11, 2024
Copy link

ti-chi-bot bot commented May 11, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-04-16 07:58:26.768149298 +0000 UTC m=+324925.879195744: ☑️ agreed by time-and-fate.
  • 2024-05-11 05:38:41.32870209 +0000 UTC m=+1286075.085837662: ☑️ agreed by xhebox.

@ti-chi-bot ti-chi-bot bot merged commit 09c8f96 into pingcap:master May 11, 2024
23 checks passed
@YangKeao YangKeao added needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. labels May 13, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #53209.

@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-6.5: #53210.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request May 13, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request May 13, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #53211.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request May 13, 2024
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.1: #53212.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-6.5 Should cherry pick this PR to release-6.5 branch. needs-cherry-pick-release-7.1 Should cherry pick this PR to release-7.1 branch. needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected SQL exception returned
4 participants