Re: prepared statements suboptimal?

From: Reg Me Please <regmeplease(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: rihad <rihad(at)mail(dot)ru>
Subject: Re: prepared statements suboptimal?
Date: 2007-11-07 11:38:27
Message-ID: 200711071238.28088.regmeplease@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Simon Riggs 2007-11-07 11:54:09 Re: Exclusive Locks Taken on User Tables?
Previous Message Simon Riggs 2007-11-07 11:34:26 Re: Postgresql simple query performance question