Re: TRIGGER with WHEN clause - Mailing list pgsql-hackers

From Tom Lane
Subject Re: TRIGGER with WHEN clause
Date
Msg-id 27430.1258657229@sss.pgh.pa.us
Whole thread Raw
In response to Re: TRIGGER with WHEN clause  (Itagaki Takahiro <itagaki.takahiro@oss.ntt.co.jp>)
List pgsql-hackers
Itagaki Takahiro <itagaki.takahiro@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


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Python 3.1 support
Next
From: Boszormenyi Zoltan
Date:
Subject: Re: Question about ECPGset_noind_null() and ECPGis_noind_null()