Skip to content

[Enhancement] union all opt #50146

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

Open
2 of 3 tasks
cambyzju opened this issue Apr 17, 2025 · 0 comments
Open
2 of 3 tasks

[Enhancement] union all opt #50146

cambyzju opened this issue Apr 17, 2025 · 0 comments

Comments

@cambyzju
Copy link
Contributor

Search before asking

  • I had searched in the issues and found no similar issues.

Description

Problem:
select * from t where k=1 union all select * from t where k=3;

should convert to:

select * from t where k=1 or k=3;

to reduce scanners

Reproduce Steps:
1、create table:

CREATE TABLE `t` (
  `k` int NULL,
  `v` int NULL
) ENGINE=OLAP
DUPLICATE KEY(`k`)
DISTRIBUTED BY HASH(`k`) BUCKETS AUTO
PROPERTIES (
"replication_allocation" = "tag.location.default: 1");

2、add data:
insert into t values(1,2),(3,4);

3、explain union all SQL

> explain shape plan select * from t where k=1 union all select * from t where k=3;
+--------------------------------------------------------+
| Explain String(Nereids Planner)                        |
+--------------------------------------------------------+
| PhysicalResultSink                                     |
| --PhysicalDistribute[DistributionSpecGather]           |
| ----PhysicalUnion                                      |
| ------PhysicalDistribute[DistributionSpecExecutionAny] |
| --------filter((t.k = 1))                              |
| ----------PhysicalOlapScan[t]                          |
| ------PhysicalDistribute[DistributionSpecExecutionAny] |
| --------filter((t.k = 3))                              |
| ----------PhysicalOlapScan[t]                          |
+--------------------------------------------------------+

4、explain equal SQL:

> explain shape plan select * from t where k=1 or k=3;
+----------------------------------------------+
| Explain String(Nereids Planner)              |
+----------------------------------------------+
| PhysicalResultSink                           |
| --PhysicalDistribute[DistributionSpecGather] |
| ----filter(k IN (1, 3))                      |
| ------PhysicalOlapScan[t]                    |
+----------------------------------------------+

Solution

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant