Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cmpF2-0006QZ-OV for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Mar 2017 22:12:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cmpF2-00012F-1n for pgsql-hackers@arkaria.postgresql.org; Sat, 11 Mar 2017 22:12:00 +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.84_2) (envelope-from ) id 1cmpDY-0006lK-QY for pgsql-hackers@postgresql.org; Sat, 11 Mar 2017 22:10:28 +0000 Received: from mimolette.dalibo.net ([212.85.157.144] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cmpDP-0003ib-RS for pgsql-hackers@postgresql.org; Sat, 11 Mar 2017 22:10:26 +0000 Received: from nol.local (unknown [78.192.238.147]) by mail.dalibo.com (Postfix) with ESMTPSA id D1D442C03D5 for ; Sat, 11 Mar 2017 23:10:17 +0100 (CET) Date: Sat, 11 Mar 2017 23:09:32 +0100 From: Julien Rouhaud To: pgsql-hackers@postgresql.org Subject: Preserving param location Message-ID: <20170311220932.GJ15188@nol.local> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="cf0hFtnykp6aONGL" Content-Disposition: inline User-Agent: Mutt/1.8.0 (2017-02-23) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --cf0hFtnykp6aONGL Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, When a query contains parameters, the original param node contains the token location. However, this information is lost when the Const node is generated, this one will only contain position -1 (unknown). FWIW, we do have a use case for this (custom extension that tracks quals statistics, which among other thing is used to regenerate query string from a pgss normalized query, thus needing the original param location). Is this something we want to get fixed? If yes, attached is a simple patch for that. Regards. -- Julien Rouhaud http://dalibo.com - http://dalibo.org --cf0hFtnykp6aONGL Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="fix_param_location-1.diff" diff --git a/src/backend/optimizer/util/clauses.c b/src/backend/optimizer/util/clauses.c index b19380e1b1..beb0f99144 100644 --- a/src/backend/optimizer/util/clauses.c +++ b/src/backend/optimizer/util/clauses.c @@ -2444,6 +2444,7 @@ eval_const_expressions_mutator(Node *node, int16 typLen; bool typByVal; Datum pval; + Const *con; Assert(prm->ptype == param->paramtype); get_typlenbyval(param->paramtype, @@ -2452,13 +2453,17 @@ eval_const_expressions_mutator(Node *node, pval = prm->value; else pval = datumCopy(prm->value, typByVal, typLen); - return (Node *) makeConst(param->paramtype, + + con = makeConst(param->paramtype, param->paramtypmod, param->paramcollid, (int) typLen, pval, prm->isnull, typByVal); + con->location = param->location; + + return (Node *) con; } } } --cf0hFtnykp6aONGL Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers --cf0hFtnykp6aONGL--