pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Graham Vickrage <graham@digitalplanit.com>
To: POSTGRES <pgsql-sql@postgresql.org>
Subject: Use of indexes in plpgsql functions
Date: Fri, 15 Dec 2000 18:36:39 -0000
Message-ID: <NDBBJABDILOPAOOMFJHOGEGOCGAA.graham@digitalplanit.com> (raw)

I have a table with 650k rows with an index on URL (pg v7.0.0 on
i686-pc-linux-gnu)

When using psql the select query behaves as expected i.e. takes < 1 second
(and explain tells me it is using the correct index)

However when I put this into a pl function it takes about 2.5 mins, Has
anyone had any similar problems/solutions or is it just that I am over
looking something??? (I know there is an update but again when executed
seperately it takes approx 1 sec)

Regards 

Graham

details as follows: -

SELECT now(); SELECT count(*) FROM statistics WHERE url ='XXX' and
website_id =1035; SELECT now();

now
----------------------
2000-12-15 19:17:34+00

count
-----
    421
(1 row)

now
----------------------
2000-12-15 19:17:35+00
(1 row)

CREATE FUNCTION get_url_hits (varchar, int4) RETURNS int4 AS '
DECLARE
	num INT4;
BEGIN
	SELECT count(*) INTO num FROM statistics WHERE url = $1 and
website_id = $2;
	
	IF num > 0 THEN
		UPDATE site_url SET hits = num, last_updated = now() where
website_id = $2 and url = $1;
	END IF;
RETURN num;
END;' LANGUAGE 'plpgsql';

select now(); select get_url_hits ('XXX', 1001); select now(); 

now
----------------------
2000-12-15 19:21:40+00
(1 row)

get_url_hits
------------
      421
(1 row)

now
----------------------
2000-12-15 19:24:06+00
(1 row)

Attachments:

  winmail.dat (application/ms-tnef, 2.2K) download

view thread (3+ messages)  latest in thread

Message-ID: <NDBBJABDILOPAOOMFJHOGEGOCGAA.graham@digitalplanit.com>
Permalink:  ../NDBBJABDILOPAOOMFJHOGEGOCGAA.graham@digitalplanit.com/
Also on:    postgresql.org/message-id/NDBBJABDILOPAOOMFJHOGEGOCGAA.graham@digitalplanit.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 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-sql@postgresql.org
  Cc: graham@digitalplanit.com
  Subject: Re: Use of indexes in plpgsql functions
  In-Reply-To: <NDBBJABDILOPAOOMFJHOGEGOCGAA.graham@digitalplanit.com>
  References: <NDBBJABDILOPAOOMFJHOGEGOCGAA.graham@digitalplanit.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