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 1wOFfi-001RCm-2p for pgsql-general@arkaria.postgresql.org; Sat, 16 May 2026 14:07:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wOFfg-0035Ns-23 for pgsql-general@arkaria.postgresql.org; Sat, 16 May 2026 14:07:16 +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 1wOFfg-0035Nj-0r for pgsql-general@lists.postgresql.org; Sat, 16 May 2026 14:07:16 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wOFfe-00000000rKk-318I for pgsql-general@lists.postgresql.org; Sat, 16 May 2026 14:07:15 +0000 Received: by mail-pj1-x1031.google.com with SMTP id 98e67ed59e1d1-3665b67ed66so393639a91.1 for ; Sat, 16 May 2026 07:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778940433; x=1779545233; darn=lists.postgresql.org; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=eoDX9RsDQ20dJrw+59VmNJYlCaE89j43s4pEIV/Y5VA=; b=JRsxsHVHNCB/mfdzFTVAFSRHnb+P58T76RA+iHEqcPd4p+R3PexNjG+gjO2jqRhA5E SVNhdgv8PJnmEm0t/zXqphOdUzJ3iRl4n0zOX1Kq3fECsJ+Qi96PtYCsAI5AW+GKQtc7 L+9aRKZtfu6HB+AZl/nZr1o4/HqK4op2+b+NAb30ZjFqs8w+QJfwDLWGgHLvtChiPQqF hS4zz4Wh1iJ8xVTj8kF8+q6oG4352XfTKaBMyLPlpEI/PjBECdLjz8VWgogP55PWfLbX CXVhX9aIBfEboQPIVi/jXayPTJm40HywVmFF/sQPAau+wbSW5Kxzozur69QojGsvrf3x gmGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778940433; x=1779545233; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=eoDX9RsDQ20dJrw+59VmNJYlCaE89j43s4pEIV/Y5VA=; b=Vk4HlEvnuGKTVblqfHmeg3cTXY+mo/FdVMgILcz4eWxq2QssmDWwfmcrMxexLUXWVt 4pYk4WNhZWty5fJCDsTKDSvTmeYtEpULc45KPBCIyasnke+2CourvNlGF9VkiXV2WfAc OoW7N+5jwGZ343jzE6bJX5ZhUYXgbSvd1kfaC9CyUZeIjShzdtH1zmEHZn/R+L8mY2vB z+ZMqvudRUaHZ8qUKWjN2l0wDsyWR+h+CFbnyE/26ajHrBP0opotMwMO3oWnbgb07tw9 n5bc16/pa6WgO7I9IrFZ6+klJ5wkH0SQSyq2FykciQuWHq5Hgy+DjZRfizmA1BIoq8NZ YaOg== X-Forwarded-Encrypted: i=1; AFNElJ8sqCwyOyHLpFXgj9HG2lt9IwbeMUr6L232qiUC4FzNipc1LRxMlS9ZiWFZNAXviinr+5PMi8fShVGrLKsB@lists.postgresql.org X-Gm-Message-State: AOJu0YzE5wOAyQr7FeEd5qQMDs78dHRfqpPsqLWQZuXtTGHsjo421RCV nDjOBUZ+8J/Slw9GgyNzIpjsz/bDv7BC6HA9b2CqhzeIaeHS2YEhlFJ3 X-Gm-Gg: Acq92OGSu66jAKlHpspDDUquidN+3S/77sRJGLC1allfe2FSN5gyNSSrDI0ehScxH66 WRlKB5NlmEQ5tB8R6A72+LyiWXxlmHBLvgmeQbn4I1nXqrECcbJepcKkl0J45KNL2CEQAx/bmIi JD3yqhKY61AUC8K/meODaMhLBMAvL8kdSPJxpiVEbD4iGfss4nmURsDl5pJMgPMEPqfP3VN0L68 rXZ0VY57dVd0BNu9Kn1GKZNq5jA4BjBcjA/9oMeglK4QFw8fScIngJWn1GxV2YJfL2xWDH4VvNC +7WR+Mc/clFR3oo+LNCLYWPsFWDgkqMcFTogEWR+8Pp8DF8K4NSNAq1EnM9l7pxKgrDdVScygWK 5dyCxUupopyUtC9C8xweoo4BTLxZkF3Dh8Z6qKhzqxgozvyOVtdcNIoOGW7lC4AuwMTDcNkMB2b fxo6agTyvC53R7FgpQSp5yMwSmlYjPmMUQ6mgBZlJQyLWpAYNp72K0sITXqt3FLF54q8N8lnGOC EAvkIbKxDUgQfTpgq+Z7ePIRylrfNA= X-Received: by 2002:a17:90b:57c7:b0:369:2e00:1ff0 with SMTP id 98e67ed59e1d1-369519c6663mr8762624a91.6.1778940433041; Sat, 16 May 2026 07:07:13 -0700 (PDT) Received: from smtpclient.apple (ec2-15-220-17-202.us-west-2.compute.amazonaws.com. [15.220.17.202]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-369517d8570sm6097846a91.14.2026.05.16.07.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 May 2026 07:07:12 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Rob Sargent Mime-Version: 1.0 (1.0) Subject: Re: Double prepare Date: Sat, 16 May 2026 08:07:01 -0600 Message-Id: <02D2D7C5-7932-4030-B65A-4BECB645E9F0@gmail.com> References: <1495292.1778939187@sss.pgh.pa.us> Cc: Igor Korot , "pgsql-generallists.postgresql.org" In-Reply-To: <1495292.1778939187@sss.pgh.pa.us> To: Tom Lane X-Mailer: iPhone Mail (23E261) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On May 16, 2026, at 7:46=E2=80=AFAM, Tom Lane wrote: >=20 > =EF=BB=BFIgor Korot writes: >> Is there a way to see if the query has been prepared already (in libpq)? >=20 > Use the pg_prepared_statements view. I don't think libpq keeps any > client-side state about this. >=20 >> Or is it better to run for all known parameterized queries >> in the very beginning of the program and just execute them when needed? >=20 > Very probably. Querying every time would be > expensive. >=20 If I am following correctly, one may query pg_prepared_statements with a spe= cific query in hand. Should it not then be possible to cache that query as h= aving been planned/prepared and proceed accordingly? Might there be value in calling PQprepare as late as possible against most u= p-to-dare data? > =20