Fix handling filter functions' memory context.

In commit edb61b5f12, the handling of sql filter functions
has been modified against PostgreSQL 9.2.4 and after.
However, this fix is not a completed one, because it does not
handle the filter functions written by other languages.
It alsoforgets to properly consider the behavior against
PostgreSQL 9.2.3 and before.