Re: Strange performance problem

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alessandro Manzoni <manzoni(dot)alessandro4(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Strange performance problem
Date: 2019-01-25 17:22:02
Message-ID: 32211.1548436922@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Alessandro Manzoni <manzoni(dot)alessandro4(at)gmail(dot)com> writes:
> Then I have a complex query that has two complete different
> performances, in these two cases:

> case a)
> with getfieldone as (select * from tableone where fieldone = 'one')
> select * from getfieldone
> inner join tabletwo on ... [and other joins]

> case b)
> select * from viewone
> inner join tabletwo on ... [and other joins, the same as case a)]

> I expected the same performance, but case a) lasts a few hundreds ms,
> while case b) lasts more than 12 seconds.

WITH is an optimization fence (at present --- there is discussion
of relaxing that) so it's not exactly surprising that these queries
perform differently. I am a little surprised though that case a)
is the faster one; usually, preventing the planner from optimizing
the whole query as one problem makes things worse.

Saying more than that would require a lot more detail.

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

regards, tom lane

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Luis Agustín Solís García-Barbón 2019-01-25 18:12:54 How upgrade version pgadmin 4
Previous Message Alessandro Manzoni 2019-01-25 17:02:24 Strange performance problem