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 1tU8D6-00EN1t-DE for pgsql-performance@arkaria.postgresql.org; Sat, 04 Jan 2025 17:45:16 +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 1tU8D5-00C9ca-Pv for pgsql-performance@arkaria.postgresql.org; Sat, 04 Jan 2025 17:45:15 +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 1tU8D5-00C9cS-EG for pgsql-performance@lists.postgresql.org; Sat, 04 Jan 2025 17:45:15 +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 1tU8D3-00257t-0d for pgsql-performance@lists.postgresql.org; Sat, 04 Jan 2025 17:45:14 +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 504HjBnW634659; Sat, 4 Jan 2025 12:45:11 -0500 From: Tom Lane To: James Addison cc: pgsql-performance@lists.postgresql.org Subject: Re: Question: consolidating strpos searches? In-reply-to: References: Comments: In-reply-to James Addison message dated "Sat, 04 Jan 2025 17:16:06 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <634657.1736012711.1@sss.pgh.pa.us> Date: Sat, 04 Jan 2025 12:45:11 -0500 Message-ID: <634658.1736012711@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk James Addison writes: > In other words: each additional strpos(value, ...) expression > increased the evaluation time by a similar, significant duration of > two seconds. This seems to confirm the basis that each expression is > currently evaluated separately, by an independent read from the input > text. That's correct. We have not felt a need to try to identify duplicate function calls: the cost of looking for them would seldom be repaid, so that such an optimization would be a net loss for most people. (In your example, they're not even truly duplicates.) > I'd like to suggest the introduction of a documented multiple string > matching algorithm[1], to yield results for each of multiple strpos > calls while only reading through their common input text at-most once. This seems like something with a pretty narrow audience. I'd suggest building it as an extension rather than trying to persuade people it belongs in core Postgres. regards, tom lane