473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

any benefit to preparing a sql function?

Is there any benefit to preparing a call to a pre-defined sql function
or is the sql function already optimized?

create temp table foo(col1 integer);
insert into foo(col1) values(1);
insert into foo(col1) values(2);
insert into foo(col1) values(3);
insert into foo(col1) values(4);
create or replace function testfunc(integer) returns foo as 'select *
from foo where col1 = $1;' language sql;
prepare myplan(integer) as select * from testfunc($1);
execute myplan(2);

They look exactly the same:

testdb=# explain execute myplan(2);
QUERY PLAN
-----------------------------------------------------------------
Function Scan on testfunc (cost=0.00..12.50 rows=1000 width=4)
(1 row)
testdb=# explain select * from testfunc(2);
QUERY PLAN
-----------------------------------------------------------------
Function Scan on testfunc (cost=0.00..12.50 rows=1000 width=4)

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #1
1 1354
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday 22 July 2004 23:58, culley harrelson wrote:
Is there any benefit to preparing a call to a pre-defined sql function
or is the sql function already optimized?

create temp table foo(col1 integer);
insert into foo(col1) values(1);
insert into foo(col1) values(2);
insert into foo(col1) values(3);
insert into foo(col1) values(4);
create or replace function testfunc(integer) returns foo as 'select *
from foo where col1 = $1;' language sql;
prepare myplan(integer) as select * from testfunc($1);
execute myplan(2);


All you get is the same result from the planner in shorter time.

- From the doc:

PREPARE creates a prepared query. A prepared query is a server-side object that
can be used to optimize performance. When the PREPARE statement is executed,
the specified query is parsed, rewritten, and planned. When a subsequent EXECUTE
statement is issued, the prepared query need only be executed. Thus, the parsing,
rewriting, and planning stages are only performed once, instead of every time the
query is executed.
Mit freundlichem Gruß / With kind regards
Holger Klawitter
- --
lists <at> klawitter <dot> de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFBALWg1Xdt0HKSwgYRAg7/AJ0ecUJ2uHqY1vFzUNhi0Gy7UpaPaQCgpAF7
AvbysHawgwmUB5TGiOzi3sE=
=A0Gw
-----END PGP SIGNATURE-----
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David | last post by:
A friend of mine has to export some data from his current access database into a CSV file to be imported into an accounting package. There are a few things that need to be done most of which I am...
0
by: matungafriend | last post by:
Hi I am fresher what kind of questions are asked during .NET Interviews how should i prepare myself.I have just completed my course from my NIIT and looking forward for real job. I am doing the...
0
by: aprajitha | last post by:
Hi, What is the approach to be followed for preparing a fresh new installation kit for a server using the Microsoft Installer?
8
by: chrisben | last post by:
Hi, If I am not sure how many items will be in my Hashtable/ArrayList dynamically (multiple threads can add/remove/check the item), however, I can estimate the total number will not exceed...
6
by: DaTurk | last post by:
Hi, I'm a bit rusty with the wonderful language of c++. I worked with it, maybe 6 or 7 years ago and now I need to knock the dust off. But I was perusing some code when I noticed that this one...
2
by: Jeff Rush | last post by:
Forrester Research is doing a study on dynamic languages and has asked that Python be represented. As advocacy coordinator I've volunteered to drive this, collecting answers from the community and...
1
by: Ciaran | last post by:
Anyone have/know of a function that will clean a html string of all tags and invalid characters, ready for an RSS feed in iso-8859-1 encoding? I'm using strip_tags at present but it's not...
0
by: alipalengara | last post by:
Hi, I have crated a setup project with prerequisites (frmaework 3.5 and SQL express 2005) and i given some custom action for restoring the database. The Problem is that after installing the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.