pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: david@lang.hm
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Scott Carey <scott@richrelevance.com>
Cc: bricklen <bricklen@gmail.com>
Cc: Scott Marlowe <scott.marlowe@gmail.com>
Cc: Merlin Moncure <mmoncure@gmail.com>
Cc: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Poor plan choice in prepared statement
Date: Tue, 30 Dec 2008 16:19:01 -0800 (PST)
Message-ID: <alpine.DEB.1.10.0812301615280.16936@asgard.lang.hm> (raw)
In-Reply-To: <2796.1230678149@sss.pgh.pa.us>
References: <33b743250812301059u31ce82faw3d72a38280b37402@mail.gmail.com>
	<b42b73150812301142w4483978ahfb819b0313150dbb@mail.gmail.com>
	<dcc563d10812301209i59bf612eidc42fa408d4441ab@mail.gmail.com>
	<33b743250812301214k7a0ec4fby614d693ec7915d3@mail.gmail.com>
	<BDFBB77C9E07BE4A984DAAE981D19F961ACD5F388E@EXVMBX018-1.exch018.msoutlookonline.net>
	<2796.1230678149@sss.pgh.pa.us>

On Tue, 30 Dec 2008, Tom Lane wrote:

> Scott Carey <scott@richrelevance.com> writes:
>> I have also had a case where one query would take a  couple hundred ms to parse, but was fairly fast to plan and execute (1/3 the parse cost) -- yet another case where a prepared statement that re-plans each execution would be helpful.  At least you can prevent SQL injection and cut the parse cost.  Its not all about the cost of planning the query.
>
> The point of a prepared statement IMHO is to do the planning only once.
> There's necessarily a tradeoff between that and having a plan that's
> perfectly adapted to specific parameter values.

actually, it does two things

1. planning only once

2. parsing only once.

I suspect that when this was initially setup the expectation was that the 
planning was the expensive thing that should be avoided.

in this case a post earlier in the thread identified parsing of the query 
as being the expensive thing (planning + execution was 1/3 the cost of the 
parsing)

since there is not a pre-parsed interface for queries, it may make sense 
to setup a way to have the query pre-parsed, but not pre-planned for cases 
like this.

David Lang



view thread (20+ messages)  latest in thread

Message-ID: <alpine.DEB.1.10.0812301615280.16936@asgard.lang.hm>
Permalink:  ../alpine.DEB.1.10.0812301615280.16936@asgard.lang.hm/
Also on:    postgresql.org/message-id/alpine.DEB.1.10.0812301615280.16936@asgard.lang.hm

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: david@lang.hm, tgl@sss.pgh.pa.us, scott@richrelevance.com, bricklen@gmail.com, scott.marlowe@gmail.com, mmoncure@gmail.com
  Subject: Re: Poor plan choice in prepared statement
  In-Reply-To: <alpine.DEB.1.10.0812301615280.16936@asgard.lang.hm>
  References: <33b743250812301059u31ce82faw3d72a38280b37402@mail.gmail.com> <b42b73150812301142w4483978ahfb819b0313150dbb@mail.gmail.com> <dcc563d10812301209i59bf612eidc42fa408d4441ab@mail.gmail.com> <33b743250812301214k7a0ec4fby614d693ec7915d3@mail.gmail.com> <BDFBB77C9E07BE4A984DAAE981D19F961ACD5F388E@EXVMBX018-1.exch018.msoutlookonline.net> <2796.1230678149@sss.pgh.pa.us> <alpine.DEB.1.10.0812301615280.16936@asgard.lang.hm>

* 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