Re: GROUP BY ROLLUP queries on views trigger full table scans (index usage not optimized) - Mailing list pgsql-bugs

From Richard Guo
Subject Re: GROUP BY ROLLUP queries on views trigger full table scans (index usage not optimized)
Date
Msg-id CAMbWs48j6BvDq9aCOM_gjgM6katSyrzpdgwoBBK1F7uD8pds4w@mail.gmail.com
Whole thread Raw
In response to Re: GROUP BY ROLLUP queries on views trigger full table scans (index usage not optimized)  ("Haowu Ge" <gehaowu@bitmoe.com>)
Responses Re: GROUP BY ROLLUP queries on views trigger full table scans (index usage not optimized)
List pgsql-bugs
On Tue, Dec 9, 2025 at 5:54 PM Haowu Ge <gehaowu@bitmoe.com> wrote:
> I built it via dpkg-buildpackage,
> but I'm unable to generate a proper installation package with the v2 patch

Hmm, I don't have much insight into the installation issue.  I tested
the v2 patch on both v18 and master, and it fixes your query.

EXPLAIN (COSTS OFF)
SELECT material_id, AVG(unit_price) as avg_price
FROM materials_view
WHERE material_id = 'PI'
GROUP BY ROLLUP(material_id);
                       QUERY PLAN
--------------------------------------------------------
 GroupAggregate
   Group Key: materials.material_id
   Group Key: ()
   ->  Index Scan using materials_pkey on materials
         Index Cond: ((material_id)::text = 'PI'::text)
(5 rows)

Regarding back-patching, I believe this issue exists before v18, but
it seems that the change in v18 made it common enough to notice,
especially in queries with grouping sets.  Given the lack of reports
for versions prior to v18, I'm inclined to back-patch this only to
v18.

Any thoughts?

- Richard



pgsql-bugs by date:

Previous
From: weijie JL
Date:
Subject: Re: BUG #19348: Disk space error when running COPY after upgrading to PostgreSQL 17.7
Next
From: Richard Guo
Date:
Subject: Re: BUG #19007: Planner fails to choose partial index with spurious 'not null'