[ 
https://issues.apache.org/jira/browse/HIVE-30261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150729#comment-18150729
 ] 

Krisztian Kasa edited comment on HIVE-30261 at 11/25/26, 8:47 AM:
------------------------------------------------------------------

Thanks for the feewdback [~zabetak]. I tried to address your comments:
{quote}It would be nice to enrich the description with at least one realistic 
SQL query with actual entities and some before and after plan representations 
that showcase the idea{quote}
Added an example query and plan. Based on the implementation in [PR 
#6963|https://github.com/apache/hive/pull/6963], I attached 
[^partial_aggr_join_transpose.q] to reproduce the case and 
[^partial_aggr_join_transpose.q.out] to show the plan changes. [PR 
#6963|https://github.com/apache/hive/pull/6963] also contains several golden 
file changes that describe the plan changes introduced by this optimization.

{quote}how many TPC-DS queries are affected and what kind of improvement we 
expect to have by applying this new optimization{quote}
The new optimization was tested on a cluster by running 99 TPC-DS queries. Here 
are the results:
Setup: TPC-DS 10 TB external Parquet, 12 nodes

Warm run (99 × 3, best of 3 per query)
||                                                 ||PAGG on||PAGG off||Diff||
| All 99 queries                                   |2,864.7 s|3,270.7 s|+14.2 %|
| 35 queries whose plan changed                    |1,015.9 s|1,387.4 s|+36.6 %|
| 64 queries with the same plan (day-to-day drift) |1,848.8 s|1,883.3 s| +1.9 %|

Cold run (99 × 1, right after start)
||                            ||PAGG on||PAGG off||Diff||
|All 99 queries               |3,484.7 s|3,919.1 s|+12.5 %|
|35 queries whose plan changes|1,269.7 s|1,658.6 s|+30.6 %|
|64 queries with the same plan|2,215.0 s|2,260.5 s| +2.1 %|

{quote}The CASE/IF part occupies half of the description but its not clear to 
me how it is connected to the optimization and why there is so much focus on 
it.{quote}
The optimization can be improved further. One planned improvement is 
case-split: GBYs with aggregates that have parameters containing CASE/IF 
expressions require extra logic to enable push-down. I moved this to a 
follow-up Jira to reduce the scope of the initial implementation. Please note 
that the numbers presented above were measured while running a version of the 
optimization improved with case-split. 


was (Author: krisztiankasa):
{quote}It would be nice to enrich the description with at least one realistic 
SQL query with actual entities and some before and after plan representations 
that showcase the idea{quote}
Added an example query and plan. Based on the implementation in [PR 
#6963|https://github.com/apache/hive/pull/6963], I attached 
[^partial_aggr_join_transpose.q] to reproduce the case and 
[^partial_aggr_join_transpose.q.out] to show the plan changes. [PR 
#6963|https://github.com/apache/hive/pull/6963] also contains several golden 
file changes that describe the plan changes introduced by this optimization.

{quote}how many TPC-DS queries are affected and what kind of improvement we 
expect to have by applying this new optimization{quote}
The new optimization was tested on a cluster by running 99 TPC-DS queries. Here 
are the results:
Setup: TPC-DS 10 TB external Parquet, 12 nodes

Warm run (99 × 3, best of 3 per query)
||                                                 ||PAGG on||PAGG off||Diff||
| All 99 queries                                   |2,864.7 s|3,270.7 s|+14.2 %|
| 35 queries whose plan changed                    |1,015.9 s|1,387.4 s|+36.6 %|
| 64 queries with the same plan (day-to-day drift) |1,848.8 s|1,883.3 s| +1.9 %|

Cold run (99 × 1, right after start)
||                            ||PAGG on||PAGG off||Diff||
|All 99 queries               |3,484.7 s|3,919.1 s|+12.5 %|
|35 queries whose plan changes|1,269.7 s|1,658.6 s|+30.6 %|
|64 queries with the same plan|2,215.0 s|2,260.5 s| +2.1 %|

{quote}The CASE/IF part occupies half of the description but its not clear to 
me how it is connected to the optimization and why there is so much focus on 
it.{quote}
The optimization can be improved further. One planned improvement is 
case-split: GBYs with aggregates that have parameters containing CASE/IF 
expressions require extra logic to enable push-down. I moved this to a 
follow-up Jira to reduce the scope of the initial implementation. Please note 
that the numbers presented above were measured while running a version of the 
optimization improved with case-split. 

> Partial GROUP BY join transpose
> -------------------------------
>
>                 Key: HIVE-30261
>                 URL: https://issues.apache.org/jira/browse/HIVE-30261
>             Project: Hive
>          Issue Type: Sub-task
>          Components: Physical Optimizer
>            Reporter: Krisztian Kasa
>            Assignee: Krisztian Kasa
>            Priority: Major
>              Labels: pull-request-available
>         Attachments: partial_aggr_join_transpose.q, 
> partial_aggr_join_transpose.q.out
>
>
> In a star join followed by a GROUP BY, the fact table rows go through the 
> shuffle and the join before any aggregation happens. When the join keys and 
> the GROUP BY keys have few distinct values on the fact side, the rows could 
> be partially aggregated below the join first. Then far fewer rows are 
> shuffled, joined and aggregated.
> h4. Exmaple query
> {code}
> select d.g, sum(f.v)
> from t_fact f
> join t_dim d on f.k = d.k
> group by d.g;
> {code}
> Plan sample
> {code}
> TS - SEL - RS \
>                JOIN - SEL - GBY(hash) - RS - GBY(mergepartial)
> TS - SEL - RS /
> {code}
> after push-down
> {code}
> TS - SEL - GBY(partialhash) - RS \
>                                   JOIN - GBY(hash) - RS - GBY(mergepartial)
> TS - SEL -------------------- RS /
> {code}
> For a detailed example see the attached files  
> [^partial_aggr_join_transpose.q] and  [^partial_aggr_join_transpose.q.out] 
> h4. Criteria to meet for push-down:
>  * The join is an inner join. Every input to the join is a ReduceSink 
> operator, and for an n-way join, every condition is an inner join.
>  * The GROUP BY is above the join with only Select operators between them. It 
> has keys, so a full aggregate cannot be pushed down.
>  * GROUP BYs with grouping sets and DISTINCT aggregations are not supported.
>  * Only SUM, $SUM0, COUNT, MIN, and MAX aggregate functions are supported. 
> These are the ones that support partial aggregation.
>  * Every key and every argument is deterministic and references at most one 
> join input.
>  * Every aggregate function argument references the same join input, and the 
> GROUP BY is pushed down to that input.
>  * If no argument has columns (e.g., COUNT(\*)), the GROUP BY is pushed down 
> to the larger join input.
>  * The pushed GROUP BY keys are not empty, and there are no more of them than 
> the original keys
> h4. Cost based criteria
>  * Statistics are available: the row counts of the join and the input to 
> which the GROUP BY is pushed down, and the column statistics of every pushed 
> key. When no argument has columns (COUNT(\*)), the row counts of every join 
> input are needed too.
>  * The join outputs at most max.join.expansion × the rows of the input to 
> which the GROUP BY is pushed down.
>  * The join reduces the input to which the GROUP BY is pushed down by at most 
> a factor of max.join.reduction. Hive has no dynamic filter on the probe side 
> of a map join, so the pushed GROUP BY would also process every row the join 
> discards.
>  * The NDV of every pushed key is at most max.key.ndv.ratio × the pushed 
> input rows.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to