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: do not remove the first row func if it is a constant | tidb-test=pr/2277 #50020

Merged
merged 5 commits into from
Jan 10, 2024

Conversation

Rustin170506
Copy link
Member

@Rustin170506 Rustin170506 commented Jan 3, 2024

What problem does this PR solve?

Issue Number: close #38756

Problem Summary:

What changed and how does it work?

Do not remove the first row func if the group by expr is a constant.

For instance, if you try SELECT DISTINCT SQRT(1) FROM t

mysql> explain SELECT DISTINCT SQRT(1) FROM t;
+---------------------------+----------+-----------+---------------+-------------------------------------------------------+
| id                        | estRows  | task      | access object | operator info                                         |
+---------------------------+----------+-----------+---------------+-------------------------------------------------------+
| HashAgg_8                 | 1.00     | root      |               | group by:Column#5, funcs:firstrow(Column#5)->Column#3 |
| └─TableReader_9           | 1.00     | root      |               | data:HashAgg_4                                        |
|   └─HashAgg_4             | 1.00     | cop[tikv] |               | group by:1,                                           |
|     └─TableFullScan_7     | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo                        |
+---------------------------+----------+-----------+---------------+-------------------------------------------------------+
4 rows in set (0.00 sec)

As you can see, we accidentally removed the first-row func because the group by expr is a constant 1 and the arg is also 1.

But if you try SELECT DISTINCT SQRT(2) FROM t, it works well.

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 TiDB issue with incorrect results when the function's argument matches the group by key

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-triage-completed release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. needs-cherry-pick-release-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.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. and removed do-not-merge/needs-triage-completed labels Jan 3, 2024
Copy link

codecov bot commented Jan 3, 2024

Codecov Report

Merging #50020 (c917924) into master (eaab02f) will decrease coverage by 14.6528%.
Report is 3 commits behind head on master.
The diff coverage is 100.0000%.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #50020         +/-   ##
=================================================
- Coverage   70.0660%   55.4132%   -14.6528%     
=================================================
  Files          1443       1554        +111     
  Lines        419720     586645     +166925     
=================================================
+ Hits         294081     325079      +30998     
- Misses       105346     238848     +133502     
- Partials      20293      22718       +2425     
Flag Coverage Δ
integration 36.6022% <0.0000%> (?)
unit 70.0199% <100.0000%> (-0.0461%) ⬇️

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

Components Coverage Δ
dumpling 54.0269% <ø> (ø)
parser ∅ <ø> (∅)
br 55.5035% <ø> (+5.8242%) ⬆️

@wuhuizuo wuhuizuo marked this pull request as draft January 8, 2024 08:54
@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 Jan 9, 2024
@ti-chi-bot ti-chi-bot bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 9, 2024
@Rustin170506 Rustin170506 changed the title WIP: test: add a case for issue 38756 planner: do not remove first row func if it is a constant Jan 9, 2024
@Rustin170506 Rustin170506 marked this pull request as ready for review January 9, 2024 06:15
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 9, 2024
@Rustin170506
Copy link
Member Author

/test all

@Rustin170506 Rustin170506 changed the title planner: do not remove first row func if it is a constant planner: do not remove the first row func if it is a constant Jan 9, 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. labels Jan 9, 2024
@Rustin170506 Rustin170506 requested review from winoros, AilinKid and elsa0520 and removed request for AilinKid January 9, 2024 06:32
Copy link
Member Author

@Rustin170506 Rustin170506 left a comment

Choose a reason for hiding this comment

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

🔢 Self-check

@Rustin170506
Copy link
Member Author

/retest

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
@Rustin170506 Rustin170506 changed the title planner: do not remove the first row func if it is a constant planner: do not remove the first row func if it is a constant | mysql-test=pr/2277 Jan 10, 2024
@Rustin170506
Copy link
Member Author

/retest

@AilinKid
Copy link
Contributor

/test mysql-test

Copy link

tiprow bot commented Jan 10, 2024

@AilinKid: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test tiprow_fast_test

Use /test all to run all jobs.

In response to this:

/test mysql-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

ti-chi-bot bot commented Jan 10, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: AilinKid, elsa0520, fixdb

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:
  • OWNERS [AilinKid,elsa0520,fixdb]

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

@Rustin170506 Rustin170506 changed the title planner: do not remove the first row func if it is a constant | mysql-test=pr/2277 planner: do not remove the first row func if it is a constant | tidb-test=pr/2277 Jan 10, 2024
@Rustin170506
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot merged commit 1a5a72a into pingcap:master Jan 10, 2024
22 checks passed
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 10, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 10, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 10, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

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

@ti-chi-bot
Copy link
Member

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

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 10, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jan 10, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

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

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-5.4 Should cherry pick this PR to release-5.4 branch. needs-cherry-pick-release-6.1 Should cherry pick this PR to release-6.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. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

value change caused by DISTINCT
5 participants