BUG #19102: Assertion failure in generate_orderedappend_paths with aggregate pushdown

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: kuntalghosh(dot)2007(at)gmail(dot)com
Subject: BUG #19102: Assertion failure in generate_orderedappend_paths with aggregate pushdown
Date: 2025-11-03 05:51:09
Message-ID: 19102-93480667e1200169@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19102
Logged by: Kuntal Ghosh
Email address: kuntalghosh(dot)2007(at)gmail(dot)com
PostgreSQL version: 18.0
Operating system: aarch64 GNU/Linux
Description:

Hi,

The assertion "Assert(childrel->rows > 0)" in generate_orderedappend_paths()
fails when processing queries where aggregates are pushed down below merge
append. In such cases, childrel can be an upperrel (grouping rel) rather
than a base relation, and will have zero row-estimates.

Steps to reproduce the issue:

CREATE TABLE pagg_tab2 (id BIGINT, PRIMARY KEY (id)) PARTITION BY RANGE
(id);
CREATE TABLE pagg_tab2_0 PARTITION OF pagg_tab2 FOR VALUES FROM ('0') TO
('1000');
CREATE TABLE pagg_tab2_1 PARTITION OF pagg_tab2 FOR VALUES FROM ('1000') TO
('2000');

SET enable_partitionwise_aggregate = true;

EXPLAIN (COSTS OFF) SELECT count(*) FROM pagg_tab2 x GROUP BY x.id ORDER
BY x.id DESC LIMIT 2;

Server crashes with assertion failure:
TRAP: FailedAssertion("childrel->rows > 0", File: "allpaths.c", Line: 1983)

To fix the issue, we can replace the direct division with
clamp_row_est(childrel->rows) to safely handle zero, and remove the
incorrect assertion:

- Assert(childrel->rows > 0);
- path_fraction /= childrel->rows;
+ path_fraction /= clamp_row_est(childrel->rows);

Thanks & regards,
Kuntal Ghosh

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kuntal Ghosh 2025-11-03 05:57:51 Re: BUG #19102: Assertion failure in generate_orderedappend_paths with aggregate pushdown
Previous Message dqetool 2025-11-03 02:48:34 Re:Re: BUG #19101: Ceil on BIGINT could lost precision in decil function