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

Unexpectedly, Distinct cannot be pushed across Projection when read partition table #18884

Closed
SunRunAway opened this issue Jul 30, 2020 · 6 comments · Fixed by #21060
Closed
Assignees
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@SunRunAway
Copy link
Contributor

SunRunAway commented Jul 30, 2020

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `tp` (
  `timestamp` timestamp NULL DEFAULT NULL,
  KEY `idx_timestamp` (`timestamp`)
) PARTITION BY RANGE ( UNIX_TIMESTAMP(`timestamp`) ) (
  PARTITION `p2020072312` VALUES LESS THAN (1595480400),
  PARTITION `p2020072313` VALUES LESS THAN (1595484000));

2. What did you expect to see? (Required)

mysql> desc select  DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tp group by tt;
+------------------------------------+----------+-----------+---------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
| id                                 | estRows  | task      | access object                   | operator info                                                                                                                     |
+------------------------------------+----------+-----------+---------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
| Projection_10                      | 16000.00 | root      |                                 | date_format(test.tp.timestamp, %Y-%m-%d %H)->Column#3                                                                             |
| └─HashAgg_13                       | 16000.00 | root      |                                 | group by:Column#5, funcs:firstrow(Column#6)->test.tp.timestamp                                                                    |
|   └─PartitionUnion_14              | 16000.00 | root      |                                 |                                                                                                                                   |
|     ├─HashAgg_17                   | 8000.00  | root      |                                 | group by:Column#15, funcs:firstrow(Column#13)->Column#6, funcs:firstrow(Column#14)->Column#5                                      |
|     │ └─Projection_37              | 10000.00 | root      |                                 | test.tp.timestamp, date_format(test.tp.timestamp, %Y-%m-%d %H)->Column#14, date_format(test.tp.timestamp, %Y-%m-%d %H)->Column#15 |
|     │   └─TableReader_23           | 10000.00 | root      |                                 | data:TableFullScan_22                                                                                                             |
|     │     └─TableFullScan_22       | 10000.00 | cop[tikv] | table:tp, partition:p2020072312 | keep order:false, stats:pseudo                                                                                                    |
|     └─HashAgg_28                   | 8000.00  | root      |                                 | group by:Column#18, funcs:firstrow(Column#16)->Column#6, funcs:firstrow(Column#17)->Column#5                                      |
|       └─Projection_38              | 10000.00 | root      |                                 | test.tp.timestamp, date_format(test.tp.timestamp, %Y-%m-%d %H)->Column#17, date_format(test.tp.timestamp, %Y-%m-%d %H)->Column#18 |
|         └─TableReader_34           | 10000.00 | root      |                                 | data:TableFullScan_33                                                                                                             |
|           └─TableFullScan_33       | 10000.00 | cop[tikv] | table:tp, partition:p2020072313 | keep order:false, stats:pseudo                                                                                                    |
+------------------------------------+----------+-----------+---------------------------------+-----------------------------------------------------------------------------------------------------------------------------------+
11 rows in set (0.01 sec)

3. What did you see instead (Required)

mysql> desc select distinct DATE_FORMAT(timestamp, '%Y-%m-%d %H') as tt from tp ;
+--------------------------------+----------+-----------+---------------------------------+-------------------------------------------------------+
| id                             | estRows  | task      | access object                   | operator info                                         |
+--------------------------------+----------+-----------+---------------------------------+-------------------------------------------------------+
| HashAgg_9                      | 16000.00 | root      |                                 | group by:Column#3, funcs:firstrow(Column#3)->Column#3 |
| └─Projection_10                | 20000.00 | root      |                                 | date_format(test.tp.timestamp, %Y-%m-%d %H)->Column#3 |
|   └─PartitionUnion_11          | 20000.00 | root      |                                 |                                                       |
|     ├─TableReader_13           | 10000.00 | root      |                                 | data:TableFullScan_12                                 |
|     │ └─TableFullScan_12       | 10000.00 | cop[tikv] | table:tp, partition:p2020072312 | keep order:false, stats:pseudo                        |
|     └─TableReader_17           | 10000.00 | root      |                                 | data:TableFullScan_16                                 |
|       └─TableFullScan_16       | 10000.00 | cop[tikv] | table:tp, partition:p2020072313 | keep order:false, stats:pseudo                        |
+--------------------------------+----------+-----------+---------------------------------+-------------------------------------------------------+
7 rows in set (0.00 sec)

4. Affected version (Required)

5. Root Cause Analysis

SIG slack channel

#sig-planner

Score

  • 900

Mentor

@SunRunAway SunRunAway added type/bug The issue is confirmed as a bug. sig/planner SIG: Planner labels Jul 30, 2020
@SunRunAway SunRunAway changed the title Unexpectedly, Distinct cannot be pushed across Projection Unexpectedly, Distinct cannot be pushed across Projection when read partition table Aug 6, 2020
@lzmhhh123 lzmhhh123 added challenge-program help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Oct 30, 2020
@Reminiscent
Copy link
Contributor

/assign

@Reminiscent
Copy link
Contributor

We need to set @@session.tidb_opt_agg_push_down = 1; for test.

@newcworld
Copy link
Contributor

hi guys, Is there anyone who is working for this? I want to have a try

@Reminiscent
Copy link
Contributor

hi guys, Is there anyone who is working for this? I want to have a try

@pengdaqian2020 Sorry, I'm working on this issue. Do you want to try other issues on #20804 ?

@ti-challenge-bot
Copy link

The issue has been removed from the challenge program.

@ti-srebot
Copy link
Contributor

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants