pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alessandro Manzoni <manzoni.alessandro4@gmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: Strange performance problem
Date: Fri, 25 Jan 2019 12:22:02 -0500
Message-ID: <32211.1548436922@sss.pgh.pa.us> (raw)
In-Reply-To: <0f9efbe6-9adc-2732-1257-b4fc0367b0f3@gmail.com>
References: <0f9efbe6-9adc-2732-1257-b4fc0367b0f3@gmail.com>

Alessandro Manzoni <manzoni.alessandro4@gmail.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




view thread (2+ messages)

Message-ID: <32211.1548436922@sss.pgh.pa.us>
Permalink:  ../32211.1548436922@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/32211.1548436922@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, manzoni.alessandro4@gmail.com
  Subject: Re: Strange performance problem
  In-Reply-To: <32211.1548436922@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox