Re: Re: BUG #8448: looping through query results exits at 10th step under some conditions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: David Johnston <polobo(at)yahoo(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Re: BUG #8448: looping through query results exits at 10th step under some conditions
Date: 2013-11-12 22:06:58
Message-ID: 14791.1384294018@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

David Johnston <polobo(at)yahoo(dot)com> writes:
> So, is there an underlying use-case driving this complaint that should be
> considered by the community either to induce a fix to the behavior or just
> to solicit suggestions for better alternatives?

While I agree the specific test case presented isn't terribly compelling,
it's not that hard to think of other scenarios where somebody might be
surprised at the presence of prefetching. Consider perhaps the
requirement "give me the next value from sequence s1 that's divisible
by ten". On its face this doesn't seem like a terrible implementation:

for s in select nextval('s1') from generate_series(1,10) loop
if s % 10 = 0 then exit loop; end if;
end loop;

This will do what's asked for but it will typically increment the sequence
several extra times due to internal prefetching. Perhaps the application
can tolerate that, perhaps not. With a user-defined volatile function,
the unwanted side effects might be quite unacceptable.

Anyway, I'm not hugely motivated to change the code to fix this, but
I think we at least ought to document it.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Jeffrey Walton 2013-11-12 23:10:28 Re: BUG #8588: Need work arounds for Apple unaligned access
Previous Message Peter Eisentraut 2013-11-12 22:00:40 Re: BUG #8588: Need work arounds for Apple unaligned access