Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gG9e4-0005i3-IR for pgsql-general@arkaria.postgresql.org; Fri, 26 Oct 2018 21:27:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gG9e0-000186-TF for pgsql-general@arkaria.postgresql.org; Fri, 26 Oct 2018 21:27:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gG9e0-000171-HD for pgsql-general@lists.postgresql.org; Fri, 26 Oct 2018 21:27:48 +0000 Received: from smtp.burggraben.net ([2a01:4f8:140:50a2::3:1]) by makus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gG9dw-000437-IW for pgsql-general@lists.postgresql.org; Fri, 26 Oct 2018 21:27:46 +0000 Received: from localhost (localhost [127.0.0.1]) by smtp.burggraben.net (Postfix) with ESMTP id DF63E6002F4 for ; Fri, 26 Oct 2018 23:27:39 +0200 (CEST) X-Spam-Scanned: by amavisd-new at exwg.net Received: from smtp.burggraben.net ([127.0.0.1]) by localhost (ns.burggraben.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lEpKnrqYBhA5 for ; Fri, 26 Oct 2018 23:27:27 +0200 (CEST) Received: from squirrel.exwg.net (unknown [88.157.232.34]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "squirrel.exwg.net", Issuer "Christoph Moench-Tegeder" (verified OK)) by smtp.burggraben.net (Postfix) with ESMTPS for ; Fri, 26 Oct 2018 23:27:27 +0200 (CEST) Received: by squirrel.exwg.net (Postfix, from userid 1000) id 42E1C162C7; Fri, 26 Oct 2018 23:27:26 +0200 (CEST) Date: Fri, 26 Oct 2018 23:27:26 +0200 From: Christoph Moench-Tegeder To: pgsql-general@lists.postgresql.org Subject: Re: rw_redis_fdw: SQL Errors when statement is within a function Message-ID: <20181026212725.33rqwraa73wpzq5f@squirrel.exwg.net> References: <20181025101948.r2hsnsm2ysn7q3ic@alap3.anarazel.de> <20181025215749.6yy3aparryceuker@squirrel.exwg.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ## 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.