Merlin Moncure <mmonc...@gmail.com> writes: > Hm, maybe, instead of trying to figure out if in a loop, set a > 'called' flag with each statement and only cache when touched the > second time. (If that's easier, dunno).
Well, then you just guarantee to lose once. I think Jan's sketch of marking potentially-cacheable expressions at compile time sounds promising. I'm envisioning a counter that starts at 1 normally or 0 in a DO block, increment at beginning of parsing a loop construct, decrement at end; then mark expressions/statements as cacheable if counter>0. Of course the next question is what exactly to do differently for a noncacheable expression. My recollection is that that's all tied pretty tightly to the plancache these days, so it might take a little work. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers