Skip to content

Conversation

0xPoe
Copy link
Member

@0xPoe 0xPoe commented May 9, 2024

What problem does this PR solve?

Issue Number: close #52933

Problem Summary:

What changed and how does it work?

From the MySQL plan:

mysql> explain analyze select var_samp(c1) over (partition by c1) from t1;
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| EXPLAIN                                                                                                                                                                                                                                                                                                                |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| -> Window aggregate with buffering: var_samp(t1.c1) OVER (PARTITION BY t1.c1 )   (cost=0 rows=1) (actual time=0.139..0.139 rows=0 loops=1)
    -> Sort: t1.c1  (cost=0.35 rows=1) (actual time=0.133..0.133 rows=0 loops=1)
        -> Table scan on t1  (cost=0.35 rows=1) (actual time=0.116..0.116 rows=0 loops=1)
 |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)

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.

Make `var_samp` can be used as a window function.
使 `var_samp` 可以用作窗口函数。

@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. do-not-merge/needs-triage-completed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed do-not-merge/needs-triage-completed labels May 9, 2024
Copy link

codecov bot commented May 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.7449%. Comparing base (4b91fee) to head (06146bb).
Report is 10 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #53130        +/-   ##
================================================
+ Coverage   74.4490%   74.7449%   +0.2959%     
================================================
  Files          1493       1493                
  Lines        356315     430968     +74653     
================================================
+ Hits         265273     322127     +56854     
- Misses        71770      89017     +17247     
- Partials      19272      19824       +552     
Flag Coverage Δ
integration 49.4982% <0.0000%> (?)
unit 71.4551% <100.0000%> (-1.7617%) ⬇️

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

Components Coverage Δ
dumpling 53.9957% <ø> (-2.3014%) ⬇️
parser ∅ <ø> (∅)
br 50.4651% <ø> (+7.4738%) ⬆️

@0xPoe
Copy link
Member Author

0xPoe commented May 10, 2024

/retest

@0xPoe 0xPoe force-pushed the rustin-patch-52933 branch from 7e8d2cd to 09db1b3 Compare May 14, 2024 06:30
@ti-chi-bot ti-chi-bot bot added sig/planner SIG: Planner size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels May 14, 2024
Signed-off-by: hi-rustin <[email protected]>
@0xPoe
Copy link
Member Author

0xPoe commented May 14, 2024

Tested locally:

  1. Start the cluster: tiup playground v8.0.0 --db.binpath /Users/hi-rustin/vsc/tidb/bin/tidb-server
  2. Create the table and run the query:
mysql> use test;
msqll> create table t1 (c1 int)
mysql> select c1, var_samp(c1) over (partition by c1) from t1;
Empty set (0.00 sec)

mysql> explain select c1, var_samp(c1) over (partition by c1) from t1;
+-------------------------------+----------+-----------+---------------+-----------------------------------------------------------------------------------+
| id                            | estRows  | task      | access object | operator info                                                                     |
+-------------------------------+----------+-----------+---------------+-----------------------------------------------------------------------------------+
| Shuffle_11                    | 10000.00 | root      |               | execution info: concurrency:5, data sources:[TableReader_9]                       |
| └─Window_7                    | 10000.00 | root      |               | var_samp(cast(test.t1.c1, double BINARY))->Column#4 over(partition by test.t1.c1) |
|   └─Sort_10                   | 10000.00 | root      |               | test.t1.c1                                                                        |
|     └─ShuffleReceiver_12      | 10000.00 | root      |               |                                                                                   |
|       └─TableReader_9         | 10000.00 | root      |               | data:TableFullScan_8                                                              |
|         └─TableFullScan_8     | 10000.00 | cop[tikv] | table:t1      | keep order:false, stats:pseudo                                                    |
+-------------------------------+----------+-----------+---------------+-----------------------------------------------------------------------------------+
6 rows in set (0.00 sec)

mysql> explain select c1, sum(c1) over (partition by c1) from t1;
+-------------------------------+----------+-----------+---------------+-------------------------------------------------------------------------------------+
| id                            | estRows  | task      | access object | operator info                                                                       |
+-------------------------------+----------+-----------+---------------+-------------------------------------------------------------------------------------+
| Shuffle_11                    | 10000.00 | root      |               | execution info: concurrency:5, data sources:[TableReader_9]                         |
| └─Window_7                    | 10000.00 | root      |               | sum(cast(test.t1.c1, decimal(10,0) BINARY))->Column#4 over(partition by test.t1.c1) |
|   └─Sort_10                   | 10000.00 | root      |               | test.t1.c1                                                                          |
|     └─ShuffleReceiver_12      | 10000.00 | root      |               |                                                                                     |
|       └─TableReader_9         | 10000.00 | root      |               | data:TableFullScan_8                                                                |
|         └─TableFullScan_8     | 10000.00 | cop[tikv] | table:t1      | keep order:false, stats:pseudo                                                      |
+-------------------------------+----------+-----------+---------------+-------------------------------------------------------------------------------------+
6 rows in set (0.01 sec)

@0xPoe 0xPoe requested review from time-and-fate and qw4990 May 14, 2024 09:28
Copy link
Member Author

@0xPoe 0xPoe 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 (PR reviewed by myself and ready for feedback.)

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

ti-chi-bot bot commented May 14, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-05-14 09:40:23.923885188 +0000 UTC m=+1559777.681020761: ☑️ agreed by qw4990.
  • 2024-05-14 12:25:15.552696005 +0000 UTC m=+1569669.309831580: ☑️ agreed by winoros.

@winoros winoros added 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. labels May 14, 2024
@winoros winoros added 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. labels May 14, 2024
@easonn7
Copy link

easonn7 commented May 15, 2024

/approve

Copy link

ti-chi-bot bot commented May 15, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: easonn7, qw4990, tangenta, winoros

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 the approved label May 15, 2024
@ti-chi-bot ti-chi-bot bot merged commit 2d552c0 into pingcap:master May 15, 2024
ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request May 15, 2024
@ti-chi-bot
Copy link
Member

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

@ti-chi-bot
Copy link
Member

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

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

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

@ti-chi-bot
Copy link
Member

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

terry1purcell pushed a commit to terry1purcell/tidb that referenced this pull request May 17, 2024
RidRisR pushed a commit to RidRisR/tidb that referenced this pull request May 23, 2024
budney pushed a commit to budney/tidb that referenced this pull request May 18, 2025
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/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.

use var_samp as window function cause unexpected error
6 participants