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.94.2) (envelope-from ) id 1tVdLy-00ABI0-Gb for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Jan 2025 21:12:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tVdLx-007ARN-Te for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Jan 2025 21:12:37 +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.94.2) (envelope-from ) id 1tVdLx-007ARF-La for pgsql-bugs@lists.postgresql.org; Wed, 08 Jan 2025 21:12:37 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tVdLv-000aSO-04 for pgsql-bugs@lists.postgresql.org; Wed, 08 Jan 2025 21:12:36 +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 508LCWSF1693905; Wed, 8 Jan 2025 16:12:32 -0500 From: Tom Lane To: Peter Eisentraut cc: "David G. Johnston" , Anmol Mohanty , pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18765: Inconsistent behaviour and errors with LIKE In-reply-to: <83c66908-ff3e-4aa1-8d90-1647d8dc8baa@eisentraut.org> References: <18765-6c26d2047e6f5143@postgresql.org> <83c66908-ff3e-4aa1-8d90-1647d8dc8baa@eisentraut.org> Comments: In-reply-to Peter Eisentraut message dated "Wed, 08 Jan 2025 21:52:29 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1693903.1736370752.1@sss.pgh.pa.us> Date: Wed, 08 Jan 2025 16:12:32 -0500 Message-ID: <1693904.1736370752@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Peter Eisentraut writes: > I have also come across this issue recently, and I think we should > actually fix it. It makes sense to verify that the pattern is > syntactically correct before trying to use it, instead of just using it > incrementally and then erroring when you happen to hit the problematic bits. I'm concerned about the performance cost of adding an extra scan of the pattern --- a scan that has exactly zero benefit in all normal use cases. Admittedly typical patterns aren't very big, but still the cost/benefit ratio is bad for most people. I wonder if we could buy back whatever it'd cost us by treating this initial scan as a "compilation" of the LIKE pattern into some form that would make the actual string search cheaper. My gut says that building a representation that contains tokens like "any character", "zero or more any characters", or "literal string of N bytes" could save some cycles while searching. In ILIKE, we could perhaps also case-fold the pattern at this stage. regards, tom lane