pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: slapo@centrum.sk
To: pgsql-performance@postgresql.org
Subject:  Re: Sub-optimal plan for a paginated query on a view with another view inside of it.
Date: Mon, 05 Aug 2013 10:14:45 +0200
Message-ID: <20130805101445.8190C260@centrum.sk> (raw)
In-Reply-To: <20130802154316.59167BB5@centrum.sk>
References: <20130802154316.59167BB5@centrum.sk>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

I apologise, I have neglected to mention Postgres versions tested. It occurs with 9.0 and 9.2
I have typo in my previous message - the sentence about vacuum, reindex and analyze should be:
"I had also run vacuum, reindex and analyze on the whole database, but it seems to have had no effect."
 
Thanks for any thoughts on the issue.
 
Peter Slapansky


______________________________________________________________
> Od: <slapo@centrum.sk>
> Komu: <pgsql-performance@postgresql.org>
> Dátum: 02.08.2013 15:43
> Predmet: Sub-optimal plan for a paginated query on a view with another view inside of it.
>

Good day,
 
I have a performance issue when JOINing a view within another view more than once.
The query takes over three seconds to execute, which is too long in this case. It's not a problem if the tables are nearly empty, but that isn't the case on the production database.
 
I suspect the planner thinks it's better to first put together the v_address view and JOIN it to the parcel table later on, but the function "fx_get_user_tree_subordinates_by_id" should be JOINed to the parcel table first, as it reduces the number of rows to less than 200 and any following JOINs would be much faster.
 
I have also ran vacuum, reindex and analyze on the whole database, but it seems to have had to effect.
 
Is there any way to nudge the planner toward that way of execution?
 
This is the query:
https://app.box.com/s/jzxiuuxoyj28q4q8rzxr <https://app.box.com/s/jzxiuuxoyj28q4q8rzxr;
 
This is the query plan:
https://app.box.com/s/u8nk6qvkjs4ae7l7dh4h <https://app.box.com/s/u8nk6qvkjs4ae7l7dh4h; (plain text)
https://app.box.com/s/jzxiuuxoyj28q4q8rzxr <https://app.box.com/s/jzxiuuxoyj28q4q8rzxr; (graphical output)
 
These are the views:
https://app.box.com/s/uibzidsazwv3eeauovuk <https://app.box.com/s/uibzidsazwv3eeauovuk; (paginated view)
https://app.box.com/s/v71vyexmdyl97m4f3m6u <https://app.box.com/s/v71vyexmdyl97m4f3m6u; (used three times in the paginated view).
 
 
Thank you.
 
Peter Slapansky

view thread (13+ messages)  latest in thread

Message-ID: <20130805101445.8190C260@centrum.sk>
Permalink:  ../20130805101445.8190C260@centrum.sk/
Also on:    postgresql.org/message-id/20130805101445.8190C260@centrum.sk

 · 

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-performance@postgresql.org
  Cc: slapo@centrum.sk
  Subject: Re:  Re: Sub-optimal plan for a paginated query on a view with another view inside of it.
  In-Reply-To: <20130805101445.8190C260@centrum.sk>

* 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