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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Segmentation fault when using a set-returning C function from a view in 8.4.0
Дата
Msg-id 11939.1249922004@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Segmentation fault when using a set-returning C function from a view in 8.4.0  (Christian Thomsen <chr@cs.aau.dk>)
Список 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 по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: machine-readable explain output v4
Следующее
От: Robert Haas
Дата:
Сообщение: Re: machine-readable explain output v4