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

Allow combining adjacent partial and final AggregateExec #5774

Closed
mingmwang opened this issue Mar 29, 2023 · 1 comment · Fixed by #5837
Closed

Allow combining adjacent partial and final AggregateExec #5774

mingmwang opened this issue Mar 29, 2023 · 1 comment · Fixed by #5837
Labels
enhancement New feature or request

Comments

@mingmwang
Copy link
Contributor

mingmwang commented Mar 29, 2023

Is your feature request related to a problem or challenge?

TPCH-Q17 physical plan:

ProjectionExec: expr=[CAST(SUM(lineitem.l_extendedprice)@0 AS Float64) / 7 as avg_yearly]
  AggregateExec: mode=Final, gby=[], aggr=[SUM(lineitem.l_extendedprice)]
    AggregateExec: mode=Partial, gby=[], aggr=[SUM(lineitem.l_extendedprice)]
      ProjectionExec: expr=[l_extendedprice@1 as l_extendedprice]
        CoalesceBatchesExec: target_batch_size=8192
          HashJoinExec: mode=CollectLeft, join_type=Inner, on=[(Column { name: "p_partkey", index: 2 }, Column { name: "l_partkey", index: 0 })], filter=BinaryExpr { left: CastExpr { expr: Column { name: "l_quantity", index: 0 }, cast_type: Decimal128(30, 15), cast_options: CastOptions { safe: false } }, op: Lt, right: CastExpr { expr: Column { name: "__value", index: 1 }, cast_type: Decimal128(30, 15), cast_options: CastOptions { safe: false } } }
            ProjectionExec: expr=[l_quantity@1 as l_quantity, l_extendedprice@2 as l_extendedprice, p_partkey@3 as p_partkey]
              CoalesceBatchesExec: target_batch_size=8192
                HashJoinExec: mode=CollectLeft, join_type=Inner, on=[(Column { name: "l_partkey", index: 0 }, Column { name: "p_partkey", index: 0 })]
                  ParquetExec: limit=None, partitions={1 group: [[/gitrepo/apache/arrow-datafusion/benchmarks/parquet_data/lineitem/part-0.parquet]]}, projection=[l_partkey, l_quantity, l_extendedprice]
                  ProjectionExec: expr=[p_partkey@0 as p_partkey]
                    CoalesceBatchesExec: target_batch_size=8192
                      FilterExec: p_brand@1 = Brand#23 AND p_container@2 = MED BOX
                        ParquetExec: limit=None, partitions={1 group: [[/gitrepo/apache/arrow-datafusion/benchmarks/parquet_data/part/part-0.parquet]]}, predicate=p_brand@3 = Brand#23 AND p_container@6 = MED BOX, pruning_predicate=p_brand_min@0 <= Brand#23 AND Brand#23 <= p_brand_max@1 AND p_container_min@2 <= MED BOX AND MED BOX <= p_container_max@3, projection=[p_partkey, p_brand, p_container]
            ProjectionExec: expr=[l_partkey@0 as l_partkey, 0.2 * CAST(AVG(lineitem.l_quantity)@1 AS Float64) as __value]
              AggregateExec: mode=Final, gby=[l_partkey@0 as l_partkey], aggr=[AVG(lineitem.l_quantity)]
                AggregateExec: mode=Partial, gby=[l_partkey@0 as l_partkey], aggr=[AVG(lineitem.l_quantity)]
                  ParquetExec: limit=None, partitions={1 group: [[/gitrepo/apache/arrow-datafusion/benchmarks/parquet_data/lineitem/part-0.parquet]]}, projection=[l_partkey, l_quantity]

We should allow combine/merge the adjacent partial and final AggregateExec in this case if there is no RepartitionExec among them.

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

No response

@mingmwang mingmwang added the enhancement New feature or request label Mar 29, 2023
@mingmwang
Copy link
Contributor Author

I'm going to add a new physical optimizer rule for this purpose. This rule should be applied after the EnforceSorting and EnforceDistribution. We might need to add new Aggregation model.

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

Successfully merging a pull request may close this issue.

1 participant