Indexes in PL/SQL

From: Tony Holmes <tony(at)crosswinds(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Indexes in PL/SQL
Date: 2003-05-30 14:33:17
Message-ID: 20030530103317.A30354@crosswinds.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I'm using PgSQL 7.3.2 and a PL/SQL routine that is posing some performance
problems for me. I have a table of users information as such (trimmed down):

user_main (
uid int4,
username character varying(32),
password character varying(16)
);

Primary Index is uid
Unique Index on username

There are approx 1.5million records in the table.

Now, on the psql command line when i do

SELECT uid FROM user_main WHERE username='bob';

it works and is very fast - the data is returned almost as fast as I can hit
enter.

Now I have a PL/SQL function (pgsql mail check):

CREATE FUNCTION valid_user(text) RETURNS text AS '
DECLARE
_user ALIAS FOR $1;
_uid user_main.uid%TYPE;
BEGIN
SELECT uid INTO _uid FROM user_main WHERE username=_user;

IF FOUND THEN
RETURN ''OK'';
END IF;

RETURN ''554 Sender Address Rejected'';
END;' LANGUAGE 'plpgsql';

It works, however, the select is taking a very long time, 5-10 seconds.

Explain doesn't help much since it's a PL/SQL routine and I could not find
any mention of this in the lists (maybe my search criteria sucked).

Any ideas?

--
Tony Holmes

Founder and Senior Systems Architect
Crosswinds Internet Communications Inc.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Joe Conway 2003-05-30 15:02:33 Re: Indexes in PL/SQL
Previous Message Terence Ng 2003-05-30 05:09:20 Re: PHP vs Cold Fusion vs Zope