Re: Segmentation fault when using a set-returning C function from a view in 8.4.0 - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Segmentation fault when using a set-returning C function from a view in 8.4.0
Date
Msg-id 11939.1249922004@sss.pgh.pa.us
Whole thread Raw
In response to Segmentation fault when using a set-returning C function from a view in 8.4.0  (Christian Thomsen <chr@cs.aau.dk>)
List pgsql-hackers
Christian Thomsen <chr@cs.aau.dk> writes:
> I have created a set-returning C function and a view that selects all
> the returned rows. When I use SELECT * FROM theview, the returned rows
> look fine. But if I use, e.g., SELECT count(*) FROM theview or SELECT
> sum(a) FROM theview, I get a segmentation fault.

> LOG:  server process (PID 7099) was terminated by signal 11:
> Segmentation fault

> Is this a bug?

Yeah, in your code: you've violated multiple rules about set-returning
functions.  Offhand:* using expectedDesc without checking for NULL* creating the tuplestore in the wrong context*
failingto set setDesc
 

Also, blindly using expectedDesc instead of constructing your own tuple
descriptor is rather badly missing the point.  This code will *only*
work for a tupdesc consisting of some number of integer columns; if
you're passed something else it will fail in more or less horrible ways.
What you're supposed to do is construct a tupdesc that accurately
describes what you're returning, and use that for the tupstore and pass
it back as setDesc.  Then the core code can verify it matches
expectedDesc.  Passing in expectedDesc is only useful for functions that
can work with a variety of actual output tupledescriptors.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: machine-readable explain output v4
Next
From: Robert Haas
Date:
Subject: Re: machine-readable explain output v4