Itagaki Takahiro <itagaki.takah...@oss.ntt.co.jp> writes: > [ TRIGGER WHEN patch ]
I'm starting to work this over now, and I've found one rather serious omission: FreeTriggerDesc doesn't free the expression tree. This means that trigger WHEN clauses will leak memory in CacheMemoryContext any time we do a relcache flush on the relation having the trigger. Over time that could be pretty nasty. There is no mechanism for freeing an expression tree explicitly, and creating one is not feasible because of the possibility of multiple references to subtrees, so this isn't trivial to fix. There are two alternatives that seem reasonable to me: * Keep the expression in nodeToString string form within the TriggerDesc structure; then it's just one more pfree in FreeTriggerDesc. The main disadvantage of this is that we'd have to repeat stringToNode every time the trigger is used. This might not be a big deal considering the other overhead of preparing an expression for execution --- check constraint expressions are handled that way IIRC --- but it's still a bit annoying. * Create a separate memory context for each TriggerDesc. This would simplify FreeTriggerDesc() to a MemoryContextDelete call, which seems attractive from both speed and code maintenance standpoints; but it would probably end up wasting a fair amount of space since the context would likely be mostly empty in most cases. Not sure which way to jump. Comments? 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