Re: Postgres not using index on views

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Justin Pryzby <pryzby(at)telsasoft(dot)com>
Cc: Rick Vincent <rvincent(at)temenos(dot)com>, pgsql-performance(at)postgresql(dot)org, Manoj Kumar <manojkumar(at)temenos(dot)com>, Herve Aubert <haubert(at)temenos(dot)com>
Subject: Re: Postgres not using index on views
Date: 2020-04-07 05:09:09
Message-ID: 26256.1586236149@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Justin Pryzby <pryzby(at)telsasoft(dot)com> writes:
> On Mon, Apr 06, 2020 at 02:19:59PM +0000, Rick Vincent wrote:
>> The following query takes an extremely long time for only 180 rows, and what this means is that we would have to index anything appearing in the where clause for every table in order to use views because the views seem not to consider the select clause. Why is that and does anyone know a way around this?

> Is there a reason why you don't store the extracted value in its own column ?

The planner seems to be quite well aware that the slower query is going to
be slower, since the estimated costs are much higher. Since it's not
choosing to optimize into a faster form, I wonder whether it's constrained
by semantic requirements. In particular, I'm suspicious that some of
those functions you have in the view are marked "volatile", preventing
them from being optimized away.

Beyond that guess, though, there's really not enough info here to say.
The info we usually ask for to debug slow-query problems is explained
at

https://wiki.postgresql.org/wiki/Slow_Query_Questions

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Laurenz Albe 2020-04-07 06:42:35 Re: Postgres not using index on views
Previous Message Justin Pryzby 2020-04-07 04:59:29 Re: Postgres not using index on views