Re: prepared statements suboptimal? - Mailing list pgsql-general

From Reg Me Please
Subject Re: prepared statements suboptimal?
Date
Msg-id 200711071238.28088.regmeplease@gmail.com
Whole thread Raw
In response to prepared statements suboptimal?  (rihad <rihad@mail.ru>)
List pgsql-general
Il Wednesday 07 November 2007 12:25:46 rihad ha scritto:
> I don't understand why postgres couldn't plan this:
> SELECT foo.e, foo.f
> FROM foo
> WHERE pk=$1 AND b=$2 AND status='1' AND c <= $3;
>
> to be later executed any slower than
>
> SELECT foo.e, foo.f
> FROM foo
> WHERE pk='abcabc' AND b='13' AND status='1' AND c <= '2007-11-20 13:14:15';

One solution is that the planner will work when it will see the query.
At that time the comparisons are all against unknown values.

Try the same with dyamical SQL, that is you dynamically build by placing the
current values instead of the $1, $2 and $3 placeholders.
In this case the planner will see the query with all current real values.
Then you execute it and compare the timings. Maybe you get better scores:
there's no warranty for better performances becasue you are going to send
the whole query again and again to the planner.

Of course you need a plpgsql function for this.
--
Reg me Please

pgsql-general by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Postgresql simple query performance question
Next
From: Simon Riggs
Date:
Subject: Re: Exclusive Locks Taken on User Tables?