Problem in contrib/tablefunc's crosstab() - Mailing list pgsql-hackers

From Tom Lane
Subject Problem in contrib/tablefunc's crosstab()
Date
Msg-id 13839.1228089327@sss.pgh.pa.us
Whole thread Raw
List pgsql-hackers
While fooling with the recent contrib problem
http://archives.postgresql.org/pgsql-committers/2008-11/msg00346.php
I noticed another way that tablefunc.c is being cavalier about the
state when it returns control: the crosstab() function returns with
an internal SPI call still active!  This is relatively harmless in
the case where it's being called by MakeTableFunctionResult; but you
can expose an error in other cases, for instance running two of 'em
in parallel:

contrib_regression=# SELECT crosstab3( 'select rowid, attribute, value  from ct  where attribute = ''att2'' or
attribute= ''att3''  order by 1,2'), crosstab3( 'select rowid, attribute, value  from ct  where attribute = ''att2'' or
attribute= ''att3''  order by 1,2');
 
ERROR:  crosstab: SPI_connect returned -1

The right way to fix this IMHO is to change the function to be called
only once and accumulate its results into a tuplestore.  That'll be
marginally more efficient, too.

Think I'll go fix this while I'm watching the football game ...
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [COMMITTERS] pgsql: Remove inappropriate memory context switch in
Next
From: "Fujii Masao"
Date:
Subject: Re: Comments to Synchronous replication patch v3