Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgYkH-0000gJ-Gr for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Jul 2018 16:59:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fgYkF-0003I9-MX for pgsql-bugs@arkaria.postgresql.org; Fri, 20 Jul 2018 16:59:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgYkF-0003I2-Gf for pgsql-bugs@lists.postgresql.org; Fri, 20 Jul 2018 16:59:07 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fgYkB-0002KC-T0 for pgsql-bugs@lists.postgresql.org; Fri, 20 Jul 2018 16:59:06 +0000 Received: from [192.168.127.1] (port=37325 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1fgYk9-0006mw-6z; Fri, 20 Jul 2018 16:59:01 +0000 Received: from [127.0.0.1] (port=16450 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1fgYk8-000LhM-Ht; Fri, 20 Jul 2018 16:59:00 +0000 From: Andrew Gierth To: pgsql-bugs@lists.postgresql.org, ipluta@wp.pl Subject: Re: BUG #15287: postgres_fdw: the "WHERE date_trunc('day', dt) = 'YYYY-MM-DD' does not push to remote. In-Reply-To: <153210427860.1404.15984608571673921883@wrigleys.postgresql.org> (PG Bug reporting form's message of "Fri, 20 Jul 2018 16:31:18 +0000") Message-ID: <87muulj28e.fsf@news-spur.riddles.org.uk> References: <153210427860.1404.15984608571673921883@wrigleys.postgresql.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Fri, 20 Jul 2018 17:59:00 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "PG" == PG Bug reporting form writes: PG> the clause: PG> WHERE date_trunc('day'::text, dt::timestamp without time zone) = 'yyyy-mm-dd' PG> does not get shipped to the foreign server. Just to expand and clarify my response from irc: This is the relevant part of the parse tree (as shown by debug_print_parse) annotated for convenience: {FUNCEXPR :funcid 2020 = date_trunc(text,timestamp without time zone) :funcresulttype 1114 = timestamp without time zone :funcretset false :funcvariadic false :funcformat 0 :funccollid 0 :inputcollid 100 = "default" :args ( {CONST :consttype 25 :consttypmod -1 :constcollid 100 = "default" :constlen -1 :constbyval false :constisnull false :location 55 :constvalue 7 [ 28 0 0 0 100 97 121 ] } {VAR -- the foreign table is the only table in the query, :varno 1 -- so this var is remote :varattno 3 :vartype 1114 = timestamp without time zone :vartypmod -1 :varcollid 0 :varlevelsup 0 :varnoold 1 :varoattno 3 :location 68 } ) :location 44 } foreign_expr_walker's FuncExpr case first walks the args, which gives an inner_cxt.state == FDW_COLLATE_NONE since the Const's collid of "default" is explicitly treated the same as InvalidOid (but note that this is NOT what assign_collations_walker did: it assigned the function's inputcollid as 100 (default), not InvalidOid). Then we get here: /* * If function's input collation is not derived from a foreign * Var, it can't be sent to remote. */ if (fe->inputcollid == InvalidOid) /* OK, inputs are all noncollatable */ ; else if (inner_cxt.state != FDW_COLLATE_SAFE || fe->inputcollid != inner_cxt.collation) return false; so with inputcollid==100 and inner_cxt.state == FDW_COLLATE_NONE, the walker bails out at this point. -- Andrew (irc:RhodiumToad)