pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Calling functions inside a function: behavior
4+ messages / 4 participants
[nested] [flat]

* Calling functions inside a function: behavior
@ 2001-04-02 11:50 Edipo Elder Fernandes de Melo <edipoelder@ig.com.br>
  2001-04-02 15:07 ` Re: Calling functions inside a function: behavior Roberto Mello <rmello@cc.usu.edu>
  0 siblings, 1 reply; 4+ messages in thread

From: Edipo Elder Fernandes de Melo @ 2001-04-02 11:50 UTC (permalink / raw)
  To: pgsql-sql

Hi all,
 

 
    I wrote a function that call another functions, like this:
 

 
FUNCTION (...) AS '(...)BEGIN
 
PERFORM FUNCTION1();
 
PERFORM FUNCTION2();
 
(...)
 
END;' LANGUAGE 'PLPGSQL';
 

 
    The problem is that takes a long time to execute (I stoped after three 
days executing). To see who taking more time to execute, I modified each one 
to return the time of its execution. Then, a made a scrip like:
 

 
SELECT TIMESTAMP 'NOW';
 
SELECT FUNCTION1();
 
SELECT FUNCTION2(); (...)
 
SELECT TIMESTAMP 'NOW';
 

 
    and, for my surprise, it take minutes to run. I read the documentation 
and I didn't found any coment abou this behavior. Can anyone explain this?
 

 
    Thank you,
 

 
    Edipo Elder
 
    [edipoelder@ig.com.br]
 

_________________________________________________________
Oi! Você quer um iG-mail gratuito?
Então clique aqui: http://www.ig.com.br/paginas/assineigmail.html




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Calling functions inside a function: behavior
  2001-04-02 11:50 Calling functions inside a function: behavior Edipo Elder Fernandes de Melo <edipoelder@ig.com.br>
@ 2001-04-02 15:07 ` Roberto Mello <rmello@cc.usu.edu>
  0 siblings, 0 replies; 4+ messages in thread

From: Roberto Mello @ 2001-04-02 15:07 UTC (permalink / raw)
  To: Edipo Elder Fernandes de Melo <edipoelder@ig.com.br>; +Cc: pgsql-sql

On Mon, Apr 02, 2001 at 08:50:32AM -0300, Edipo Elder Fernandes de Melo wrote:
>  
>     and, for my surprise, it take minutes to run. I read the documentation 
> and I didn't found any coment abou this behavior. Can anyone explain this?

	Cool, one more Brazilian in the list :)

	I don't see any difference between calling the functions with a select
or a perform, except that with perform the return value is discarded.
	What version of PG are you running and what are those functions
written in (PL/pgSQL, PL/Tcl, PL/Perl)?
	Can you post a snippet of the functions here?

	-Roberto
-- 
+----| http://fslc.usu.edu USU Free Software & GNU/Linux Club |------+
  Roberto Mello - Computer Science, USU - http://www.brasileiro.net 
       http://www.sdl.usu.edu - Space Dynamics Lab, Developer    
TOFU -> Text Oben Fullquote Unten



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Fwd: Calling functions inside a function: behavior
@ 2001-04-02 17:20 Josh Berkus <josh@agliodbs.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Josh Berkus @ 2001-04-02 17:20 UTC (permalink / raw)
  To: pgsql-sql

Edipo,
 
> FUNCTION (...) AS '(...)BEGIN 
> PERFORM FUNCTION1(); 
> PERFORM FUNCTION2(); 
> (...) 
> END;' LANGUAGE 'PLPGSQL'; 

I'm not sure about that syntax (PERFORM).  I ususally set my functions
equal to a value ('remote_result := Function1(paramater)').  This has
the added advantage of letting me use an exit value from my sensted
function to communicate with the parent function ('IF remote_result =
'ERROR' THEN ... ').  I'm just not sure what bugaboos you may be running
into with PERFORM.

One possibility (Tom, Jan, verify me on this):  All calls in a function
are automatically nested in a transaction.  Thus, if FunctionM calls
Function1, 2, and 3, then the system should reverse Functions 1, 2, and
3 if M errors out at any point.  This means that all of the changes made
by the nested calls need to be cached somehow; on a slow or low-memory
system, this could lead to bogging down as your machine utilizes its
swap space if Functions 1, 2, and 3 involve heavy data interactions.

One way to test this, is to modify your test script as follows:

BEGIN WORK;
PERFORM Function1;
SELECT current_timestamp;
PERFORM Function2;
SELECT current_timestamp;
etc ...
COMMIT WORK;

If the test script bogs down as well, you have your answer although the
workaround may be tricky to implement.

-Josh Berkus




______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Fwd: Calling functions inside a function: behavior
@ 2001-04-02 20:47 edipoelder@ig.com.br
  0 siblings, 0 replies; 4+ messages in thread

From: edipoelder@ig.com.br @ 2001-04-02 20:47 UTC (permalink / raw)
  To: pgsql-sql

Em 02 Apr 2001, Josh Berkus escreveu: 

>BEGIN WORK; 
>COMMIT WORK; 

    In time... I think that could be great if postgresql implement a commit 
inside functions. 

    Abracos, 

    Edipo Elder 
    [edipoelder@ig.com.br] 

_________________________________________________________
Oi! Você quer um iG-mail gratuito?
Então clique aqui: http://www.ig.com.br/paginas/assineigmail.html




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2001-04-02 20:47 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-04-02 11:50 Calling functions inside a function: behavior Edipo Elder Fernandes de Melo <edipoelder@ig.com.br>
2001-04-02 15:07 ` Roberto Mello <rmello@cc.usu.edu>
2001-04-02 17:20 Fwd: Calling functions inside a function: behavior Josh Berkus <josh@agliodbs.com>
2001-04-02 20:47 Re: Fwd: Calling functions inside a function: behavior edipoelder@ig.com.br

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