pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bo Lorentsen <bl@netgroup.dk>
To: pgsql-sql <pgsql-sql@postgresql.org>
Subject: Large data sets and FOR LOOP's
Date: 13 Mar 2002 10:37:21 +0100
Message-ID: <1016012241.1094.90.camel@netgroup> (raw)

Hi ...

I have been working on some server side scripts in Plpgsql and I'm quite
happy about them (nice and fast way to work with large data sets) :-)

But, if I, in my code, make "for loop" on a huge select result (about
1.7 mil. rows), my function begin to consume alot of memory. The code
looks like this : 

FOR trec IN SELECT f1,f2 FROM large_tabel LOOP
	...
END LOOP;

When selecting the result with a small limit (about 1000) the function
still consumes much memory, but when the function is successfully done
the memory are freed nicely again. When using the full select I run out
of memory (I got 2G in this mashine + swap :-)).

Are there a way to release this memory, or would a cursor be the answer.
Does Plpgsql not use normal scope rules in FOR LOOP's ?

Anyway, I fixed the problem by removing the topmost FOR loop, and then
called the function from a SELECT, multibly times. Like this :

SELECT myfunc( f1, f2 ) FROM large_table;

Is this a known issue, or is it at bug, or are there something I have
misunderstood ?

Who maintain the part of PostgreSQL, anyway ?

/BL 






view thread (7+ messages)  latest in thread

Message-ID: <1016012241.1094.90.camel@netgroup>
Permalink:  ../1016012241.1094.90.camel@netgroup/
Also on:    postgresql.org/message-id/1016012241.1094.90.camel@netgroup

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bl@netgroup.dk
  Subject: Re: Large data sets and FOR LOOP's
  In-Reply-To: <1016012241.1094.90.camel@netgroup>

* 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