Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iEJTX-0007ys-Th for pgsql-general@arkaria.postgresql.org; Sat, 28 Sep 2019 20:37:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iEJTW-0004m5-ML for pgsql-general@arkaria.postgresql.org; Sat, 28 Sep 2019 20:37:54 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iEJTW-0004ld-CO for pgsql-general@lists.postgresql.org; Sat, 28 Sep 2019 20:37:54 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iEJTT-00058Q-Lx for pgsql-general@lists.postgresql.org; Sat, 28 Sep 2019 20:37:54 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x8SKbhdT032759; Sat, 28 Sep 2019 16:37:43 -0400 From: Tom Lane To: Andrew Gierth cc: Alastair McKinley , "pgsql-general\@lists.postgresql.org" Subject: Re: Possible bug: SQL function parameter in window frame definition In-reply-to: <87tv8wmn1i.fsf@news-spur.riddles.org.uk> References: <87tv8wmn1i.fsf@news-spur.riddles.org.uk> Comments: In-reply-to Andrew Gierth message dated "Sat, 28 Sep 2019 16:59:55 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32757.1569703063.1@sss.pgh.pa.us> Date: Sat, 28 Sep 2019 16:37:43 -0400 Message-ID: <32758.1569703063@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrew Gierth writes: > "Alastair" == Alastair McKinley writes: > Alastair> This appears to be a bug to me. > Yes, it's a bug, related to function inlining (the select f(3); is not > inlined and therefore works, but the select * from f(3); is being > inlined, but the original Param is somehow making it into the final plan > rather than being substituted with its value). Looking into why. It looks to me that the reason is that query_tree_mutator (likewise query_tree_walker) fails to visit query->windowClause, which is a bug of the first magnitude if we allow those to contain expressions. Not sure how we've missed that up to now. Looking at struct Query, it seems like that's not the only questionable omission. We're also not descending into Node *utilityStmt; /* non-null if commandType == CMD_UTILITY */ List *groupClause; /* a list of SortGroupClause's */ List *groupingSets; /* a list of GroupingSet's if present */ List *distinctClause; /* a list of SortGroupClause's */ List *sortClause; /* a list of SortGroupClause's */ List *rowMarks; /* a list of RowMarkClause's */ Now probably this is never called on utility statements, and maybe there is never a reason for anyone to examine or mutate SortGroupClauses, GroupingSets, or RowMarkClauses, but I'm not sure it's any business of this module to assume that. regards, tom lane