Skip to content

[Enhancement] union all opt #50146

Closed
Closed
@cambyzju

Description

@cambyzju

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions