From: | Andres Freund <andres(at)2ndquadrant(dot)com> |
---|---|
To: | Itai <itaid(at)outlook(dot)com> |
Cc: | "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Crash on SRF execution |
Date: | 2015-03-15 16:03:38 |
Message-ID: | 20150315160338.GC9324@alap3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
On 2015-03-15 17:59:39 +0200, Itai wrote:
> Thanks for the quick response!! :)
> But I don't get it... isn't:
> if (SRF_IS_FIRSTCALL()){
> }
> the iterator one time
> "initialization block" where I setup the data to be iterated
> upon?
>
> Can you please elaborate on how should I fix this? I'm probably missing something basic...
> > > if (SRF_IS_FIRSTCALL())
> > > {
> > > length = 4000;
> > > base_num = 1203000000;
> > > list = (NumberList *)palloc(sizeof(NumberList));
> > > list->pp_numbers = (Number **)palloc(sizeof(Number*) * length);
You allocate memory in the per call context here.
> > > list->length = length;
> > > i = 0;
> > > for (; i < length; i++)
> > > {
> > > num = (Number *)palloc(sizeof(Number));
> > > num->value = base_num + i;
> > > num->is_even = ((base_num + i) % 2 == 0) ? 1 : 0;
> > > list->pp_numbers[i] = num;
> > > }
> > > ereport(INFO, (errmsg("----------- data source -----------")));
> > > i = 0;
> > > for (; i < length; i++)
> > > {
> > > ereport(INFO, (errmsg("value: %d", list->pp_numbers[i]->value)));
> > > ereport(INFO, (errmsg("is_even: %d", list->pp_numbers[i]->is_even)));
> > > }
> > >
> > > funcctx = SRF_FIRSTCALL_INIT();
> > > oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
Because you only switch the memory context here. Move this up, to the
beginning of the SRF_IS_FIRSTCALL block. Before the palloc()s.
Greetings,
Andres Freund
--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
From | Date | Subject | |
---|---|---|---|
Next Message | Itai | 2015-03-15 16:20:21 | Re: Crash on SRF execution |
Previous Message | Itai | 2015-03-15 15:59:39 | Re: Crash on SRF execution |