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 archives
  Advanced Search

Re: plpgsql functions vs. embedded queries


  • From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
  • To: "Wright, George" <George(dot)Wright(at)infimatic(dot)com>
  • Cc: "John DeSoi" <desoi(at)pgedit(dot)com>, pgsql-novice(at)postgresql(dot)org
  • Subject: Re: plpgsql functions vs. embedded queries
  • Date: Tue, 30 Sep 2008 09:37:14 -0400
  • Message-id: <11123.1222781834@sss.pgh.pa.us> <text/plain>

"Wright, George" <George(dot)Wright(at)infimatic(dot)com> writes:
> Hope this isn't too much detail. The prepared statement was barely
> faster and the raw stored proc was much slower.

Well, here's your problem:
 
> CREATE OR REPLACE FUNCTION TestStoredProc(integer, text, text) RETURNS

$2 and $3 presumably ought to be timestamp with time zone, not text.
In the prepared statement those parameters default to being of the same
type as what they're compared to.  Here, you've forced a textual
comparison to occur, which doesn't match the index on alert_data,
so you end up with a slow seqscan ... and possibly not even the
right answers, if the supplied dates are formatted at all strangely.

(8.3 would have saved you from this mistake, btw, because it won't
do implicit casts to text.)

			regards, tom lane



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group