Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAx4w-0001aj-Pm for pgsql-general@arkaria.postgresql.org; Fri, 21 Jan 2022 16:47:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nAx4v-0006Fl-LD for pgsql-general@arkaria.postgresql.org; Fri, 21 Jan 2022 16:47:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAx4v-0006Fb-Au for pgsql-general@lists.postgresql.org; Fri, 21 Jan 2022 16:47:57 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nAx4t-0002zM-7v for pgsql-general@lists.postgresql.org; Fri, 21 Jan 2022 16:47:57 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 20LGlr1A1191690; Fri, 21 Jan 2022 11:47:53 -0500 From: Tom Lane To: Dominique Devienne cc: pgsql-general@lists.postgresql.org Subject: Re: Does PostgreSQL do bind-peeking? Is `col like '%'` optimized-away by the planner? In-reply-to: References: Comments: In-reply-to Dominique Devienne message dated "Fri, 21 Jan 2022 17:38:43 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1191688.1642783673.1@sss.pgh.pa.us> Date: Fri, 21 Jan 2022 11:47:53 -0500 Message-ID: <1191689.1642783673@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Dominique Devienne writes: > Will the query planner be able to *peek* into the args, and turn the > `colN like $N` > into a no-op? No. It would not do that even if the pattern were constant '%'; it doesn't know that much about that particular function. There is a notion of "custom plans" in which parameter values are inserted as constants, precisely to allow simplifications based on known constant values. But this particular case isn't implemented. I am entirely unfamiliar with the terminology "bind-peeking", so I can't say whether that's effectively the same thing as our custom plans. regards, tom lane