pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris <dmagick@gmail.com>
To: David Kerr <dmk@mr-paradox.net>
Cc: Craig Ringer <craig@postnewspapers.com.au>
Cc: pgsql-performance@postgresql.org
Subject: Re: Optimizer + bind variables
Date: Wed, 04 Nov 2009 11:02:22 +1100
Message-ID: <4AF0C48E.8090100@gmail.com> (raw)
In-Reply-To: <20091103235245.GA77360@mr-paradox.net>
References: <20091103174729.GA55736@mr-paradox.net>
	<4AF0C014.4090000@postnewspapers.com.au>
	<20091103235245.GA77360@mr-paradox.net>

David Kerr wrote:
> On Wed, Nov 04, 2009 at 07:43:16AM +0800, Craig Ringer wrote:
> - David Kerr wrote:
> - > Does/is it possible for the PG optimizer come up with differnet plans when 
> - > you're using bind variables vs when you send static values?
> - 
> - Yes, if the bind variable form causes your DB access driver to use a
> - server-side prepared statement. Pg can't use its statistics to improve
> - its query planning if it doesn't have a value for a parameter when it's
> - building the query plan.
> 
> hmm, that's a little unclear to me.
> 
> let's assume that the application is using prepare:
> 
> Assuming the database hasn't changed, would:
> PREPARE bla1 as SELECT * from users where username = '$1';
> explain execute bla1
> 
> give the same output as
> explain select * from users where username = 'dave';
> 
> ?

No.

This is explained in the notes here:

http://www.postgresql.org/docs/current/static/sql-prepare.html

-- 
Postgresql & php tutorials
http://www.designmagick.com/




view thread (6+ messages)  latest in thread

Message-ID: <4AF0C48E.8090100@gmail.com>
Permalink:  ../4AF0C48E.8090100@gmail.com/
Also on:    postgresql.org/message-id/4AF0C48E.8090100@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: dmagick@gmail.com, dmk@mr-paradox.net, craig@postnewspapers.com.au
  Subject: Re: Optimizer + bind variables
  In-Reply-To: <4AF0C48E.8090100@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox