Re: Sharing data between stored functions?

From: Igor Neyman <ineyman(at)perceptron(dot)com>
To: inspector morse <inspectormorse86(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Sharing data between stored functions?
Date: 2015-03-05 14:58:53
Message-ID: A76B25F2823E954C9E45E32FA49D70ECC230E3C1@mail.corp.perceptron.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of inspector morse
Sent: Thursday, March 05, 2015 9:21 AM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] Sharing data between stored functions?

I have written a simple web application using pure pl/pgsql and so far it is working really well (I find it quite easy to maintain as well especially in terms of form validation).
Basically, apache/php passes receives the incoming web request and calls a "serve_page" function in postgresql passing the querystring and post values.
The serve_page declares 5 temporary tables to store querystring values, post values, validation messages, and general data that is going to be shared between the functions.
Then it parses the page url and calls the appropriate "page render" stored function.
Throughout the "building" the web page, several of the temporary tables are written too (about 20-30 rows total would be add to the temporary table).
Once the page "html" is built, the temporary tables are dropped and the HTML is sent back to php to write to the response stream.

I read in the documentation that temporary tables can cause catalog bloat or performance issues.....in my context (where only 20-30 rows are written every request and the table is dropped after rending), could it cause an issue for many incoming requests?

You’d be better off not creating/dropping temp tables every time.

Just create global temp tables once with “ON COMMIT PRESERVE ROWS“ option, and when any session uses them their contents will be private to this session.

Regards,

Igor Neyman

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2015-03-05 15:10:37 Re: Sharing data between stored functions?
Previous Message Kevin Grittner 2015-03-05 14:41:54 Re: autovacuum worker running amok - and me too ;)