Search Postgresql Archives

Re: prepared statements suboptimal?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
       message can get through to the mailing list cleanly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux