Re: Index not used in certain nested views but not in others

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Markus Demleitner <msdemlei(at)ari(dot)uni-heidelberg(dot)de>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Index not used in certain nested views but not in others
Date: 2025-05-01 04:58:45
Message-ID: 91e617539ff887f1aac4e27bf1481b51fcf4b131.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 2025-04-30 at 17:02 -0400, Tom Lane wrote:
> Markus Demleitner <msdemlei(at)ari(dot)uni-heidelberg(dot)de> writes:
> > So, when the SELECT statement on dfbsspec.ssa stands along in the view
> > definition, Postgres does the right thing; when the exact same query
> > stands in a UNION ALL with other tables, Postgres doesn't use the
> > index. Hu?
>
> It's hard to be sure when you've shown us no table definitions and
> only fragments of the view definitions. But I suspect what is
> happening here is that the view's UNIONs are causing a data type
> coercion of raw_spectra.pub_did before it gets to the top level
> of the view output. That might interfere with the planner's ability
> to see that the outer query's join operator is compatible with
> the table's index.

For a more detailed description of that problem, see
https://www.cybertec-postgresql.com/en/union-all-data-types-performance/

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message KK CHN 2025-05-01 07:53:00 Pgbackrest : Resumable backup of same type exists
Previous Message Tom Lane 2025-04-30 21:02:09 Re: Index not used in certain nested views but not in others