dbTalk Databases Forums  

[NOVICE] Partitions are not excluded in stored procedures

mailing.database.pgsql-novice mailing.database.pgsql-novice


Discuss [NOVICE] Partitions are not excluded in stored procedures in the mailing.database.pgsql-novice forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ioannis Anagnostopoulos
 
Posts: n/a

Default [NOVICE] Partitions are not excluded in stored procedures - 06-05-2012 , 10:56 AM






Hi there,

I came across the following problem. Say I have a select query that
given the appropriate where clauses it will only query the correct
partitioned tables and not all of them. That can be examined by using
the EXPLAIN. However the same select query used in a stored procedure
will transverse all the tables regardless of the where clause parameters
passed by the user as variables of the stored procedure . Is there any
work around other than composing an EXECUTE "select ....."?

Kind Regards
Yiannis


--
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [NOVICE] Partitions are not excluded in stored procedures - 06-05-2012 , 11:55 AM






Ioannis Anagnostopoulos <ioannis (AT) anatec (DOT) com> writes:
Quote:
I came across the following problem. Say I have a select query that
given the appropriate where clauses it will only query the correct
partitioned tables and not all of them. That can be examined by using
the EXPLAIN. However the same select query used in a stored procedure
will transverse all the tables regardless of the where clause parameters
passed by the user as variables of the stored procedure . Is there any
work around other than composing an EXECUTE "select ....."?
Yeah, if the WHERE clauses that correspond to the partitioning
constraints contain parameters, the planner can't prove the exclusions
hold. So you have to use EXECUTE to get a one-shot plan. This will
be better in 9.2 (which, basically, will automatically recognize that
it needs to use one-shot plans).

regards, tom lane

--
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
  #3  
Old   
Ioannis Anagnostopoulos
 
Posts: n/a

Default Re: [NOVICE] Partitions are not excluded in stored procedures - 06-06-2012 , 03:10 AM



On 05/06/2012 17:55, Tom Lane wrote:
Quote:
Ioannis Anagnostopoulos<ioannis (AT) anatec (DOT) com> writes:
I came across the following problem. Say I have a select query that
given the appropriate where clauses it will only query the correct
partitioned tables and not all of them. That can be examined by using
the EXPLAIN. However the same select query used in a stored procedure
will transverse all the tables regardless of the where clause parameters
passed by the user as variables of the stored procedure . Is there any
work around other than composing an EXECUTE "select ....."?
Yeah, if the WHERE clauses that correspond to the partitioning
constraints contain parameters, the planner can't prove the exclusions
hold. So you have to use EXECUTE to get a one-shot plan. This will
be better in 9.2 (which, basically, will automatically recognize that
it needs to use one-shot plans).

regards, tom lane
When you say better in 9.2 you mean that we will be able to avoid the
EXECUTE, and the plan will be, more or less, calculated per call without
great performance hit?

Regards and thank you
Yiannis

--
Sent via pgsql-novice mailing list (pgsql-novice (AT) postgresql (DOT) org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

Reply With Quote
  #4  
Old   
Marcelo Sena
 
Posts: n/a

Default Re: [NOVICE] Partitions are not excluded in stored procedures - 06-09-2012 , 01:21 PM



I might be misunderstanding but I think that what Tom meant is that the
EXPLAIN does not try to guess whether
the constraint will actually exclude some data, so it show you a
pessimistic estimate of the cost.

If I'm right, using EXPLAIN ANALYZE should show that the query considers
any constraint clauses in your query.

Cheers,
Marcelo Lacerda

On 06/06/2012 05:10 AM, Ioannis Anagnostopoulos wrote:

On 05/06/2012 17:55, Tom Lane wrote:

Ioannis Anagnostopoulos<ioannis (AT) anatec (DOT) com> <ioannis (AT) anatec (DOT) com> writes:

I came across the following problem. Say I have a select query that
given the appropriate where clauses it will only query the correct
partitioned tables and not all of them. That can be examined by using
the EXPLAIN. However the same select query used in a stored procedure
will transverse all the tables regardless of the where clause parameters
passed by the user as variables of the stored procedure . Is there any
work around other than composing an EXECUTE "select ....."?

Yeah, if the WHERE clauses that correspond to the partitioning
constraints contain parameters, the planner can't prove the exclusions
hold. So you have to use EXECUTE to get a one-shot plan. This will
be better in 9.2 (which, basically, will automatically recognize that
it needs to use one-shot plans).

regards, tom lane

When you say better in 9.2 you mean that we will be able to avoid the
EXECUTE, and the plan will be, more or less, calculated per call without
great performance hit?

Regards and thank you
Yiannis

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.