Re: Eager aggregation, take 3
Matheus Alcantara <matheusssilv97@gmail.com>
Attachments
- query-31.master.explain (text/plain)
- query-31.patch.explain (text/plain)
[ getting back to testing this patch ...]
On my last email you replied:
>> Debugging this query shows that all if conditions on
>> setup_eager_aggregation() returns false and create_agg_clause_infos()
>> and create_grouping_expr_infos() are called. The RelAggInfo->agg_useful
>> is also being set to true so I would expect to see Finalize and Partial
>> agg nodes, is this correct or am I missing something here?
>
> Well, just because eager aggregation *can* be applied does not mean
> that it *will* be; it depends on whether it produces a lower-cost
> execution plan. This transformation is cost-based, so it's not the
> right mindset to assume that it will always be applied when possible.
>
Sorry for the noise here. I didn't consider the costs.
On Sun Sep 28, 2025 at 11:09 PM -03, Richard Guo wrote:
> On Thu, Sep 25, 2025 at 1:23 PM Richard Guo <guofenglinux@gmail.com> wrote:
>> Attached is an updated version of the patch with these optimizations
>> applied.
>
> FWIW, I plan to do another self-review of this patch soon, with the
> goal of assessing whether it's ready to be pushed. If anyone has any
> concerns about any part of the patch or would like to review it, I
> would greatly appreciate hearing from you.
>
I spent some time testing patch v23 using the TPC-DS benchmark and am
seeing worse execution times when using eager aggregation.
The most interesting cases are:
Query | planning time | execution time |
query 31 | -2.03% │ -99.56% │
query 71 | -15.51% │ -68.88% │
query 20 | -10.77% │ -32.40% │
query 26 | -28.01% │ -32.35% │
query 85 | -10.57% │ -31.91% │
query 77 | -30.07% │ -31.38% │
query 69 | -32.79% │ -29.21% │
query 32 | -68.48% │ -27.89% │
query 57 | -7.99% │ -27.32% │
query 91 | -24.81% │ -26.20% │
query 23 | -11.72% │ -18.24% │
The query 31 seems bad, I don't know if I'm doing something completely
wrong but I've just setup a TPC-DS database and then executed the query
on master and with the v23 patch and I got these results:
Master:
Planning Time: 3.191 ms
Execution Time: 16950.619 ms
Patch:
Planning Time: 3.257 ms
Execution Time: 3848355.646 ms
Note that I've executed ANALYZE before running the queries on both
scenarios (master and patched).
I'm attaching an EXPLAIN(ANALYZE) output for the query 31 from master
and with the patch applied.
Please let me know if there is any other test that I can run to
benchmark this patch.
--
Matheus Alcantara
Commits
-
Fix eager aggregation for semi/antijoin inner rels
- ffeda04259bb 19 (unreleased) landed
-
Cover additional errors and corner conditions in repack.c
- 2670cc298f42 19 (unreleased) cited
-
Fix volatile function evaluation in eager aggregation
- 3a08a2a8b4fd 19 (unreleased) landed
-
Fix collation handling for grouping keys in eager aggregation
- bd94845e8c90 19 (unreleased) landed
-
Rename apply_at to apply_agg_at for clarity
- 1206df04c200 19 (unreleased) landed
-
Fix comment in eager_aggregate.sql
- 36fd8bde1b77 19 (unreleased) landed
-
Remove unnecessary include of "utils/fmgroids.h"
- f997d777adf7 19 (unreleased) landed
-
Implement Eager Aggregation
- 8e11859102f9 19 (unreleased) landed
-
Allow negative aggtransspace to indicate unbounded state size
- 185e30426334 19 (unreleased) landed
-
Add macros for looping through a List without a ListCell.
- 14dd0f27d7cd 17.0 cited
-
Account for the effect of lossy pages when costing bitmap scans.
- 5edc63bda68a 11.0 cited
-
Fix a thinko in join_is_legal: when we decide we can implement a semijoin
- a43b190e3c71 9.0.0 cited