Re: rw_redis_fdw: SQL Errors when statement is within a function - Mailing list pgsql-general

From Christoph Moench-Tegeder
Subject Re: rw_redis_fdw: SQL Errors when statement is within a function
Date
Msg-id 20181026212725.33rqwraa73wpzq5f@squirrel.exwg.net
Whole thread Raw
In response to Re: rw_redis_fdw: SQL Errors when statement is within a function  (GPT <gptmailinglists@gmail.com>)
Responses Re: rw_redis_fdw: SQL Errors when statement is within a function  (GPT <gptmailinglists@gmail.com>)
List pgsql-general
## GPT (gptmailinglists@gmail.com):

> I have searched in
> https://github.com/nahanni/rw_redis_fdw/blob/master/redis_fdw.c for
> PREPARE and EXECUTE keywords. There are not any of them, except in
> comments.

Of course not - the FDW does not execute SQL on the PostgreSQL side,
but sends commands to redis.
Still, the FDW operations are part of PostgreSQL's query plan; they
have to be - everything PostgreSQL does is organized in plans, and the
operations done on the Foreign Server (redis in this case) have to
have their interfaces in the plan.

And the important thing is: there is no guarantee that the same SQL
statement will always execute with the same plan: One reason would be
changing table statistics, another is when PostgreSQL switches to
the generic plan for a prepared statement. Your case looks like the
latter, especially the observation "After that (6th time)" in
https://github.com/nahanni/rw_redis_fdw/issues/13#issuecomment-428670890
hints to that.
So, where does that prepared statement come from? You don't really
describe your environment... It's unlikely that you're calling PREPARE
yourself - but some drivers are notorious for that (Perl DBI's
$dbh->prepare() or JDBC's PreparedStatement come to mind), and
even PL/pgSQL uses prepared statements internally:
https://www.postgresql.org/docs/11/static/plpgsql-implementation.html#PLPGSQL-PLAN-CACHING

So: plans are not stable between query executions, and you may have
prepared statements without knowing that.

Regards,
Christoph

-- 
Spare Space.


pgsql-general by date:

Previous
From: Thomas Munro
Date:
Subject: Re: Different memory allocation strategy in Postgres 11?
Next
From: Jeff Janes
Date:
Subject: Re: GIN Index for low cardinality