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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Christian Thomsen <chr(at)cs(dot)aau(dot)dk>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Segmentation fault when using a set-returning C function from a view in 8.4.0
Date: 2009-08-10 16:33:24
Message-ID: 11939.1249922004@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Christian Thomsen <chr(at)cs(dot)aau(dot)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
* failing to 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2009-08-10 16:39:00 Re: machine-readable explain output v4
Previous Message Alvaro Herrera 2009-08-10 16:28:05 Re: machine-readable explain output v4