The following bug has been logged on the website:
Bug reference: 19102
Logged by: Kuntal Ghosh
Email address: kuntalghosh.2007@gmail.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