pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: John Meinel <john@johnmeinel.com>
Cc: pgsql-hackers-win32 <pgsql-hackers-win32@postgresql.org>
Cc: pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Poor Performance for large queries
Date: Wed, 29 Sep 2004 09:40:11 +0100
Message-ID: <415A74EB.9040308@archonet.com> (raw)
In-Reply-To: <415A575F.2060802@johnmeinel.com>
References: <4155C955.40808@dunslane.net>
	<415A288F.2030002@johnmeinel.com>
	<22682.1096434647@sss.pgh.pa.us>
	<415A575F.2060802@johnmeinel.com>

John Meinel wrote:
> 
> So notice that when doing the actual select it is able to do the index 
> query. But for some reason with a prepared statement, it is not able to 
> do it.
> 
> Any ideas?

In the index-using example, PG knows the value you are comparing to. So, 
it can make a better estimate of how many rows will be returned. With 
the prepared/compiled version it has to come up with a plan that makes 
sense for any value.

If you look back at the explain output you'll see PG is guessing 181,923 
rows will match with the prepared query but only 1 for the second query. 
If in fact you returned that many rows, you wouldn't want to use the 
index - it would mean fetching values twice.

The only work-around if you are using plpgsql functions is to use 
EXECUTE to make sure your queries are planned for each value provided.

-- 
   Richard Huxton
   Archonet Ltd



view thread (3+ messages)  latest in thread

Message-ID: <415A74EB.9040308@archonet.com>
Permalink:  ../415A74EB.9040308@archonet.com/
Also on:    postgresql.org/message-id/415A74EB.9040308@archonet.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: dev@archonet.com, john@johnmeinel.com, pgsql-hackers-win32@postgresql.org
  Subject: Re: [PERFORM] Poor Performance for large queries
  In-Reply-To: <415A74EB.9040308@archonet.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