pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: kuntalghosh.2007@gmail.com
Subject: BUG #19102: Assertion failure in generate_orderedappend_paths with aggregate pushdown
Date: Mon, 03 Nov 2025 05:51:09 +0000
Message-ID: <19102-93480667e1200169@postgresql.org> (raw)

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



view thread (13+ messages)  latest in thread

Message-ID: <19102-93480667e1200169@postgresql.org>
Permalink:  ../19102-93480667e1200169@postgresql.org/
Also on:    postgresql.org/message-id/19102-93480667e1200169@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, kuntalghosh.2007@gmail.com
  Subject: Re: BUG #19102: Assertion failure in generate_orderedappend_paths with aggregate pushdown
  In-Reply-To: <19102-93480667e1200169@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox