Re: How to write a function that manipulates a set of results

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Ashley Moran <work(at)ashleymoran(dot)me(dot)uk>, Andreas Kretschmer <akretschmer(at)spamfence(dot)net>, PostgreSQL General <pgsql-general(at)postgresql(dot)org>, Tony Caduto <tony_caduto(at)amsoftwaredesign(dot)com>
Subject: Re: How to write a function that manipulates a set of results
Date: 2007-03-15 00:21:06
Message-ID: 27260.1173918066@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> Ashley Moran wrote:
>> Also I'm unsure how the use of temporary tables will affect the
>> running of the query. This function will be called up to 400 times
>> by a wrapping function that needs to complete quickly (relatively -
>> the calculations need to return in a few seconds). I haven't had
>> chance to read much about PG temp tables yet, so I don't know how the
>> implementation works. Are small tables stored in RAM, or does
>> creating a temporary table always force a disk write?

> Temp tables stay in RAM until they are bigger than temp_buffers. If you
> need them to be big and quick, maybe it would be appropriate to use
> indexes (note these count towards temp_buffers), ANALYZE, etc.

You do need to realize that creation of a temp table involves making
entries in the system catalogs. If you can set it up so that you reuse
the same temp table(s) for the life of a connection, you'll save a lot
of thrashing and need for catalog vacuuming (the ON COMMIT DELETE ROWS
option for temp tables might help here). Other than that gotcha, they
should be pretty efficient.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Randall Smith 2007-03-15 00:59:26 Re: [Bulk] Re: quoted identifier behaviour
Previous Message Kenneth Downs 2007-03-15 00:09:24 plperl function called > once in cascading triggers