Обсуждение: Plperl caching prepared queries and cleanup

Поиск
Список
Период
Сортировка

Plperl caching prepared queries and cleanup

От
Anupama
Дата:
Hi,

I am trying to use plperl for one of my triggers. The trigger executes a
query.
So I am preparing the query and caching it as below:

        if (!defined $_SHARED{'base_table_query'}) {

            my $base_columns_query = "select column_name from
                                    information_schema.columns where
table_schema = '$_TD->{table_schema}'
                                    and table_name = \$1";
            $_SHARED{'base_table_query'} =
spi_prepare($base_columns_query, 'text');
        }

        $result = spi_exec_prepared($_SHARED{'base_table_query'},
$base_table_name);

Now, in a batch update (involving 1000s of records), the trigger itself
fires for each update.
I will get maximum performance benefit, if I can keep the prepared query
in the global cache across trigger invocation.

In effect, there is no logical point to call spi_freeplan()

Will the plan be freed when the db session / connection closes OR
Will it lead to any memory leaks ?

Thanks
Anupama.



Re: Plperl caching prepared queries and cleanup

От
Alex Hunsaker
Дата:
On Thu, Dec 16, 2010 at 01:57, Anupama <anupama.mr@gmail.com> wrote:
> Will the plan be freed when the db session / connection closes OR

Yes.  However results may vary with a connection pooler.

FYI %_SHARED is global to session, not database global. (technically
its global per perl interpreter, so plperl and plperlu have different
%_SHARED).

> Will it lead to any memory leaks ?

Not unless you consider the act of storing something in %_SHARED a leak.