Shall I convert all my stored procedure to use "EXECUTE", to ensure I get index-scan

From: Yan Cheng Cheok <yccheok(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Shall I convert all my stored procedure to use "EXECUTE", to ensure I get index-scan
Date: 2010-01-22 09:49:50
Message-ID: 442776.1596.qm@web65708.mail.ac4.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

By refering to http://archives.postgresql.org/pgsql-general/2010-01/msg00846.php

It solves speed problem in stored procedure, which use function parameter, during its SQL query.

Does this means, I shall convert *ALL* my stored procedure, which use function parameter during its SQL query, to use EXECUTE, to ensure I always get index-scan?

For example :

convert :

CREATE OR REPLACE FUNCTION update_lot_end_timestamp(bigint)
RETURNS timestamp AS
$BODY$DECLARE
_lotID ALIAS FOR $1;
_timestamp timestamp;
BEGIN
_timestamp = now();
UPDATE lot SET timestamp = _timestamp WHERE lot_id = _lotID;
return _timestamp;
END;$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION update_lot_end_timestamp(bigint) OWNER TO postgres;

to

CREATE OR REPLACE FUNCTION update_lot_end_timestamp(bigint)
RETURNS timestamp AS
$BODY$DECLARE
_lotID ALIAS FOR $1;
_timestamp timestamp;
BEGIN
_timestamp = now();
EXECUTE 'UPDATE lot SET timestamp = $1 WHERE lot_id = $2'
USING _timestamp, _lotID;
return _timestamp;
END;$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION update_lot_end_timestamp(bigint) OWNER TO postgres;

Is there any rule of thumb to follow?

Thanks and Regards
Yan Cheng CHEOK

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alan Millington 2010-01-22 10:27:20 Re: Error "invalid byte sequence for encoding UTF8" on insert into BYTEA column
Previous Message Alex - 2010-01-22 09:00:34 Re: Slow Query / Check Point Segments