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 1nCjpz-0003sQ-9P for pgsql-general@arkaria.postgresql.org; Wed, 26 Jan 2022 15:03:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nCjpx-00081t-DQ for pgsql-general@arkaria.postgresql.org; Wed, 26 Jan 2022 15:03:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCjpx-00081k-3G for pgsql-general@lists.postgresql.org; Wed, 26 Jan 2022 15:03:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nCjpu-00029I-Pd for pgsql-general@lists.postgresql.org; Wed, 26 Jan 2022 15:03:52 +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 20QF3mvg2438894; Wed, 26 Jan 2022 10:03:48 -0500 From: Tom Lane To: Julien Rouhaud cc: Dominique Devienne , Matthias Apitz , Josef =?utf-8?B?xaBpbcOhbmVr?= , pgsql-general Subject: Re: SELECT with LIKE clause makes full table scan In-reply-to: <20220126135139.uik5gbuzyxybxq4x@jrouhaud> References: <20220126121306.k6ilsxl7vy2ppmjn@jrouhaud> <20220126135139.uik5gbuzyxybxq4x@jrouhaud> Comments: In-reply-to Julien Rouhaud message dated "Wed, 26 Jan 2022 21:51:39 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2438892.1643209428.1@sss.pgh.pa.us> Date: Wed, 26 Jan 2022 10:03:48 -0500 Message-ID: <2438893.1643209428@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Julien Rouhaud writes: > On Wed, Jan 26, 2022 at 02:34:21PM +0100, Dominique Devienne wrote: >> On Wed, Jan 26, 2022 at 1:13 PM Julien Rouhaud wrote: >>> That index can't be used with a LIKE that has a trailing wildcard. >> So what makes you say that? --DD > This part of the documentation you mentioned: >> However, if your database does not use the C locale you will need to create >> the index with a special operator class to support indexing of >> pattern-matching queries; see Section 11.10 below. Note that declaring the index with C collation should also work, and might be preferable to using the pattern_ops opclass. C collation has at least some chance of being used explicitly in queries, whereas a pattern_ops index is basically never going to match anything but LIKE/regex searches. regards, tom lane