From: | Scott Carey <scott(at)richrelevance(dot)com> |
---|---|
To: | Michal J(dot)Kubski <michal(dot)kubski(at)cdt(dot)pl>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: query planning different in plpgsql? |
Date: | 2009-10-29 16:43:56 |
Message-ID: | C70F145C.1577D%scott@richrelevance.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On 10/23/09 8:38 AM, "Michal J.Kubski" <michal(dot)kubski(at)cdt(dot)pl> wrote:
>
>
>
>
> Hi,
>
>
>
> Is there any way to get the query plan of the query run in the stored
>
> procedure?
>
> I am running the following one and it takes 10 minutes in the procedure
>
> when it is pretty fast standalone.
>
>
>
> Any ideas would be welcome!
>
>
If your query is
SELECT field, field2 FROM table1 WHERE field3 = 'xxx' AND field4 = 'yyy'
And you want to test what the planner will do without the knowledge of the
exact values 'xxx' and 'yyy', you can prepare a statement:
#PREPARE foo() AS SELECT field, field2 FROM table1 WHERE field3 = $1 AND
field4 = $2;
#EXPLAIN execute foo('xxx', 'yyy');
If field3 and field4 don't have unique indexes, the plan might differ. It
will most likely differ if 'xxx' or 'yyy' is a very common value in the
table and the table is not tiny.
From | Date | Subject | |
---|---|---|---|
Next Message | Scott Marlowe | 2009-10-29 16:59:48 | Re: database size growing continously |
Previous Message | Steve Crawford | 2009-10-29 16:40:01 | Re: database size growing continously |