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 CAMbWs49h5F66KZwLxaeXoLwHe_9jAB7Eu44UmJhhQpLA38tKhw@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
I've been back and forth on whether to back-patch these two patches to
v18, given that they can lead to plan changes.

To recap: in v18, we fixed a correctness issue regarding grouping sets
by wrapping Var expressions in PHVs.  While necessary, it had the side
effect of making these expressions opaque to the planner: the planner
can no longer match these expressions to indexes or look up their
statistics.  As reported here, this causes a severe performance
regression in v18 compared to previous versions.

The proposed fix is to teach the planner to look through these PHVs
when matching indexes or looking up statistics.  While this fixes the
regression, it can lead to plan changes, which we want to avoid in
back branches.

However, I'm still inclined to back-patch this to v18 (and no
further), because:

1. The fix only affects queries involving PHVs in indexable or
statistical contexts.  The regression tests show that only one
existing query is affected, and in a positive way.  So the impact is
pretty scoped.

2. For the affected queries, the current behavior is arguably broken:
the planner is forced to ignore valid indexes and fall back to default
selectivity estimates.  I think the fix is an improvement.

3. If we do not back-patch, this severe performance regression will
remain in v18 forever.

Having said that, back-patching a change that affects query plans
still keeps me up at night.  Any thoughts?

- Richard



pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #19365: postgres 18 pg_dump fails whan drop sequence concurrently
Next
From: Amit Kapila
Date:
Subject: Re: BUG #19360: Bug Report: Logical Replication initial sync fails with "conflict=update_origin_differs" PG12 toPG18