pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christoph Moench-Tegeder <cmt@burggraben.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: rw_redis_fdw: SQL Errors when statement is within a function
Date: Fri, 26 Oct 2018 23:27:26 +0200
Message-ID: <20181026212725.33rqwraa73wpzq5f@squirrel.exwg.net> (raw)
In-Reply-To: <CADep2PNC2f57EL8ZtKb999oXvYWNBok74m033xMRG4AFw03fMQ@mail.gmail.com>
References: <CADep2PPVOo68kRsC0yDF0X_neUGd8pduTKnmyDp0RSaDajTuEg@mail.gmail.com>
	<20181025101948.r2hsnsm2ysn7q3ic@alap3.anarazel.de>
	<CADep2PN_T+frUJG07oKRJ0DfUALuuoaSbvKq_nposNNaSWjX2w@mail.gmail.com>
	<20181025215749.6yy3aparryceuker@squirrel.exwg.net>
	<CADep2PNC2f57EL8ZtKb999oXvYWNBok74m033xMRG4AFw03fMQ@mail.gmail.com>

## 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.




view thread (25+ messages)  latest in thread

Message-ID: <20181026212725.33rqwraa73wpzq5f@squirrel.exwg.net>
Permalink:  ../20181026212725.33rqwraa73wpzq5f@squirrel.exwg.net/
Also on:    postgresql.org/message-id/20181026212725.33rqwraa73wpzq5f@squirrel.exwg.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: cmt@burggraben.net
  Subject: Re: rw_redis_fdw: SQL Errors when statement is within a function
  In-Reply-To: <20181026212725.33rqwraa73wpzq5f@squirrel.exwg.net>
  References: <CADep2PPVOo68kRsC0yDF0X_neUGd8pduTKnmyDp0RSaDajTuEg@mail.gmail.com> <20181025101948.r2hsnsm2ysn7q3ic@alap3.anarazel.de> <CADep2PN_T+frUJG07oKRJ0DfUALuuoaSbvKq_nposNNaSWjX2w@mail.gmail.com> <20181025215749.6yy3aparryceuker@squirrel.exwg.net> <CADep2PNC2f57EL8ZtKb999oXvYWNBok74m033xMRG4AFw03fMQ@mail.gmail.com> <20181026212725.33rqwraa73wpzq5f@squirrel.exwg.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox