Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1veqDW-000unI-0D for pgsql-hackers@arkaria.postgresql.org; Sun, 11 Jan 2026 07:50:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1veqDT-00BSqF-2d for pgsql-hackers@arkaria.postgresql.org; Sun, 11 Jan 2026 07:50:28 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1veqDT-00BSq6-1c for pgsql-hackers@lists.postgresql.org; Sun, 11 Jan 2026 07:50:28 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1veqDT-005UVj-00 for pgsql-hackers@lists.postgresql.org; Sun, 11 Jan 2026 07:50:27 +0000 Received: by mail-pg1-x541.google.com with SMTP id 41be03b00d2f7-c525de78ebaso1430068a12.3 for ; Sat, 10 Jan 2026 23:50:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768117826; x=1768722626; darn=lists.postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=HhA5A1Q9cBx9pjuyTOCmPTWlCTkBn5Dy5soPbVGY2Ks=; b=PwUz10ss3LnCpxR8AZlTCBW2ZefTKIvvJZtyO8a/q66AUdqB0Nyf9G49l6NcAQ1UKz 7Njx70mWOODbpsvsW0HTqQwcrZG0lsIQUTY3XdCryEhpkBNZA2yoEPkR365Dqril1jLX 7s4ZToe4LZKhGx/S8OinfPjsO+nNsW6eeTUCKXUcJvQr7NhuA0z4nETx3nnbHAgKL2Lf dox+Wki/AHwOjt/D7a1gUcRp/UhS0DOlnnDzEnc043Y29/Ti1ofGBCRJmfv38SZ/NZ/g QNbx1N/U8woy6q9JISnPKW2wuB6WyTOhttoRRxG6J0hnAmMD2Yuc4dpVTio6niMNhASd d3/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768117826; x=1768722626; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HhA5A1Q9cBx9pjuyTOCmPTWlCTkBn5Dy5soPbVGY2Ks=; b=Lw7cUKkT66RzUfhAmpxn95S/aXz4kVvLPQbBbyeKdPCq32WU5KTyO+cLWBnhZw8ves Rm1lCIKt4c/NgsbZGwABAwj5XEsP+g5F/4pszKEoObJMcmP4DobhPhsbdNUGdvfmhSdm siO90UqSTMa7keUvj28HFUgCZ1Jf24GvF7E8FZWxYbym1cp26wiJZpi10z9eXOIKiDEu QXxO8cMlbD5eytwIR0lkbKDX6QQLnxXjybvK/V9WG3VGlDgNF6peOh7svLdZUyFxT7sU SK3oe/wWXovuYe78IrJWemEou0Z4hZ3aT2zC32WBSqtW56BEzO++sDphfNoPB7iWholF Zr1Q== X-Gm-Message-State: AOJu0YymUFnaeHRgadgcD0nFfGnsEKrjJGI64dxuvf1bTZOfb/8AXQ64 VeZxD3we3fnhirXJrW61GMjlp/u8TpUr/lK0dkIj/DJelqqCWNA9xVvtQbDdrZ49 X-Gm-Gg: AY/fxX5HOnIwS5vUkDx/5IB3v7W+5sBPHbtHT1pxrH6/C/pepW3QS8i/v1XJLP4LKCG aHGBgavF/efzvnoXGhjjZpc8Ys6r1PZkkJgNUk1xAjZFzfzhG+FxLAWhocl0ojmGL4t75vIYAgE 1vwqRKubmFFqaY/hAT1idas2DkXooLdbj2ZxnQYi5muFChqgp+gdmI4XrIevaK7herxGhWp+76K 7yn1uGI1qkZyT/UdV3Z0S1sd8aTT/c6gXJ0je93/tTFaGPkB3yyN8fd1UwF6uRS9XmjDpx1Gp9V G1hvTw1Va6tB1fsFwYAA7J/gHw78yWWlDDrmg9smY/uxbLCg6r0IdCGvaf2rlcvVoAmEKDRHkmr HmL/oEDpmcMgp163BV0VUytycfQD3fv9nII1NvcTnNH90Y4cOjfFWiWDwbI2kzJO423EWz555ML fK/GU= X-Google-Smtp-Source: AGHT+IHhC5XvKXaqSMocM2i15qeoy82gY3nV6Iu0GC2itiB9kgjpwnGWb7dftZSdofSwV2sz3Rukcw== X-Received: by 2002:a17:90b:1f8e:b0:34c:3501:d11c with SMTP id 98e67ed59e1d1-34f68c47f87mr13747706a91.37.1768117825537; Sat, 10 Jan 2026 23:50:25 -0800 (PST) Received: from jrouhaud ([115.43.41.38]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-81e3eb854e3sm5992530b3a.5.2026.01.10.23.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Jan 2026 23:50:24 -0800 (PST) Date: Sun, 11 Jan 2026 15:50:19 +0800 From: Julien Rouhaud To: Tom Lane Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Cleaning up PREPARE query strings? Message-ID: References: <928501.1766593260@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <928501.1766593260@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Wed, Dec 24, 2025 at 11:21:00AM -0500, Tom Lane wrote: > Julien Rouhaud writes: > > I'm attaching a POC patch to fix that behavior by teaching PREPARE to clean the > > passed query text the same way as pg_stat_statements. > > This patch invalidates all the location fields in the parsed query: > they could not be used to generate sane error cursors referencing the > truncated string. I'm not sure how many places try to generate such > errors post-parsing, but it's more than zero, and I've long had > ambitions of trying to extend that substantially (e.g, allowing > execution-time errors from functions to point at the relevant function > call). Ah I wasn't aware of that. After a quick look I'm assuming it's all the callers of executor_errposition()? There aren't a lot of them, and I've unfortunately been unable to hit any of them. Every scenario I tried was always caught during planning time. Do you have any example on how to exercise them? > Certainly the patch could be extended to update all those fields, > but that increases its complexity very significantly. I doubt > that it's worth it. My reaction to your example is more like > "if that bothers you, don't do it that way". I agree that updating the location fields in the whole parsetree is a non starter, butt I don't think that it's the only option. If that's indeed the cases going through executor_errposition(), they rely on having the executor state at hand to retrieve the query string. We could simply have an extra "query string offset" field stored there that would always be 0 except when PREPARE changes the input query string and then do the location to character number calculation after applying that offset. And that offset should already be returned by CleanQuerytext() so it wouldn't have extra complication.