Re: [HACKERS] Endless loop calling PL/Python set returning functions

2016-04-05 Thread Tom Lane
Alexey Grishchenko writes: > Any comments on this patch? I felt that this was more nearly a bug fix than a new feature, so I picked it up even though it's nominally in the next commitfest not the current one. I did not like the code too much as it stood: you were not being paranoid enough about

Re: [HACKERS] Endless loop calling PL/Python set returning functions

2016-03-22 Thread Alexey Grishchenko
Alexey Grishchenko wrote: > Alexey Grishchenko wrote: > >> Tom Lane wrote: >> >>> Alexey Grishchenko writes: >>> > No, my fix handles this well. >>> > In fact, with the first function call you allocate global variables >>> > representing Python function input parameters, call the function and

Re: [HACKERS] Endless loop calling PL/Python set returning functions

2016-03-11 Thread Alexey Grishchenko
Alexey Grishchenko wrote: > Tom Lane wrote: > >> Alexey Grishchenko writes: >> > No, my fix handles this well. >> > In fact, with the first function call you allocate global variables >> > representing Python function input parameters, call the function and >> > receive iterator over the functi

Re: [HACKERS] Endless loop calling PL/Python set returning functions

2016-03-10 Thread Alexey Grishchenko
Tom Lane wrote: > Alexey Grishchenko > writes: > > No, my fix handles this well. > > In fact, with the first function call you allocate global variables > > representing Python function input parameters, call the function and > > receive iterator over the function results. Then in a series of Pos

Re: [HACKERS] Endless loop calling PL/Python set returning functions

2016-03-10 Thread Tom Lane
Alexey Grishchenko writes: > No, my fix handles this well. > In fact, with the first function call you allocate global variables > representing Python function input parameters, call the function and > receive iterator over the function results. Then in a series of Postgres > calls to PL/Python ha

Re: [HACKERS] Endless loop calling PL/Python set returning functions

2016-03-10 Thread Alexey Grishchenko
No, my fix handles this well. In fact, with the first function call you allocate global variables representing Python function input parameters, call the function and receive iterator over the function results. Then in a series of Postgres calls to PL/Python handler you just fetch next value from

Re: [HACKERS] Endless loop calling PL/Python set returning functions

2016-03-10 Thread Tom Lane
Alexey Grishchenko writes: > One scenario when the problem occurs, is when you are calling the same > set-returning function in a single query twice. This way they share the > same "globals" which is not a bad thing, but when one function finishes > execution and deallocates input parameter's glob

Re: [HACKERS] Endless loop calling PL/Python set returning functions

2016-03-10 Thread Alexey Grishchenko
I agree that passing function parameters through globals is not the best solution It works in a following way - executing custom code (in our case Python function invocation) in Python is made with PyEval_EvalCode . As an input to this C function you

Re: [HACKERS] Endless loop calling PL/Python set returning functions

2016-03-10 Thread Tom Lane
Alexey Grishchenko writes: > There is a bug in implementation of set-returning functions in PL/Python. > When you call the same set-returning function twice in a single query, the > executor falls to infinite loop which causes OOM. Ugh. > Another issue with calling the same set-returning functio

[HACKERS] Endless loop calling PL/Python set returning functions

2016-03-10 Thread Alexey Grishchenko
Hello There is a bug in implementation of set-returning functions in PL/Python. When you call the same set-returning function twice in a single query, the executor falls to infinite loop which causes OOM. Here is a simple reproduction for this issue: CREATE OR REPLACE FUNCTION func(iter int) RETU