Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6FwR-0002Gr-Bz for pgsql-performance@arkaria.postgresql.org; Mon, 05 Aug 2013 08:14:59 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V6FwQ-0005lq-H9 for pgsql-performance@arkaria.postgresql.org; Mon, 05 Aug 2013 08:14:58 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6FwK-0005db-Bk for pgsql-performance@postgresql.org; Mon, 05 Aug 2013 08:14:52 +0000 Received: from gmmr7.centrum.cz ([2a00:da80:0:502::5]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V6FwG-000370-Ie for pgsql-performance@postgresql.org; Mon, 05 Aug 2013 08:14:51 +0000 Received: from mail1005.cent (unknown [10.32.3.100]) by gmmr7.centrum.cz (Postfix) with ESMTP id CE5358039BE1 for ; Mon, 5 Aug 2013 10:14:45 +0200 (CEST) Received: by mail1005.cent (Postfix, from userid 33) id C71326005C0E4; Mon, 5 Aug 2013 10:14:45 +0200 (CEST) To: Subject: =?utf-8?q?Re=3A_Sub=2Doptimal_plan_for_a_paginated_query_on_a_view_with_another_view_inside_of_it=2E?= Received: from 195.168.8.115 (X-Forwarded-For: 195.168.8.115) by mail1005.centrum.cz (centrum.cz multimail) with HTTP Date: Mon, 05 Aug 2013 10:14:45 +0200 From: References: <20130802154316.59167BB5@centrum.sk> In-Reply-To: <20130802154316.59167BB5@centrum.sk> X-Mailer: Centrum Email 5.3 X-Priority: 3 X-Original-From: slapo@centrum.sk MIME-Version: 1.0 Message-Id: <20130805101445.8190C260@centrum.sk> X-Maser: Georgo X-Pg-Spam-Score: -1.9 (-) Content-Type: multipart/alternative; boundary="_d32c_-------59afe6e5a358e0daf8b21ad827807b89" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org This is a multi-part message in MIME format. --_ca29_-------82bc3f7aa1caacba80c8b5cf060015e7 Content-Type: multipart/alternative; boundary="_d32c_-------59afe6e5a358e0daf8b21ad827807b89" --_d32c_-------59afe6e5a358e0daf8b21ad827807b89 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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: > Komu: > 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   This is the query plan: https://app.box.com/s/u8nk6qvkjs4ae7l7dh4h (plain text) https://app.box.com/s/jzxiuuxoyj28q4q8rzxr (graphical output)   These are the views: https://app.box.com/s/uibzidsazwv3eeauovuk (paginated view) https://app.box.com/s/v71vyexmdyl97m4f3m6u (used three times in the paginated view).     Thank you.   Peter Slapansky --_d32c_-------59afe6e5a358e0daf8b21ad827807b89 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

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
 
This is the query plan:
https://app.box.com/s/u8nk6qvkjs4ae7l7dh4h (plain text)
https://app.box.com/s/jzxiuuxoyj28q4q8rzxr (graphical output)
 
These are the views:
https://app.box.com/s/uibzidsazwv3eeauovuk (paginated view)
https://app.box.com/s/v71vyexmdyl97m4f3m6u (used three times in the paginated view).
 
 
Thank you.
 
Peter Slapansky

--_d32c_-------59afe6e5a358e0daf8b21ad827807b89-- --_ca29_-------82bc3f7aa1caacba80c8b5cf060015e7--