Re: postgres_fdw : altering foreign table not invalidating prepare statement execution plan.

Amit Langote <langote_amit_f8@lab.ntt.co.jp>

From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: Rajkumar Raghuwanshi <rajkumar.raghuwanshi@enterprisedb.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2016-04-04T08:45:01Z
Lists: pgsql-hackers

Attachments

Hi,

Thanks for the report.

On 2016/04/04 15:17, Rajkumar Raghuwanshi wrote:
> Hi,
> 
> I observed below in postgres_fdw
> 
> * .Observation: *Prepare statement execution plan is not getting changed
> even after altering foreign table to point to new schema.
> 

[ ... ]

> PREPARE stmt_ft AS select c1,c2 from ft;
> 
> EXECUTE stmt_ft;
>  c1 |  c2
> ----+-------
>   1 | s1.lt
> (1 row)
> 
> --changed foreign table ft pointing schema from s1 to s2
> ALTER foreign table ft options (SET schema_name 's2', SET table_name 'lt');
> ANALYZE ft;
> 
> EXPLAIN (COSTS OFF, VERBOSE) EXECUTE stmt_ft;
>                QUERY PLAN
> ----------------------------------------
>  Foreign Scan on public.ft
>    Output: c1, c2
>    Remote SQL: SELECT c1, c2 FROM s1.lt
> (3 rows)

I wonder if performing relcache invalidation upon ATExecGenericOptions()
is the correct solution for this problem.  The attached patch fixes the
issue for me.

Thanks,
Amit

Commits

  1. Invalidate cached plans on FDW option changes.