Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: [PERFORM] Poor Performance for large queries


  • From: Richard Huxton <dev(at)archonet(dot)com>
  • To: John Meinel <john(at)johnmeinel(dot)com>
  • Cc: pgsql-hackers-win32 <pgsql-hackers-win32(at)postgresql(dot)org>, pgsql-performance(at)postgresql(dot)org
  • Subject: Re: [PERFORM] Poor Performance for large queries
  • Date: Wed, 29 Sep 2004 09:40:11 +0100
  • Message-id: <415A74EB(dot)9040308(at)archonet(dot)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



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group