Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ft1bo-0000EG-Ps for pgsql-general@arkaria.postgresql.org; Fri, 24 Aug 2018 02:13:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ft1bn-0007V9-5I for pgsql-general@arkaria.postgresql.org; Fri, 24 Aug 2018 02:13:55 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ft1bm-0007Ux-Pu for pgsql-general@lists.postgresql.org; Fri, 24 Aug 2018 02:13:54 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ft1bk-0000pq-Dn for pgsql-general@postgresql.org; Fri, 24 Aug 2018 02:13:53 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w7O2DUD3026281; Thu, 23 Aug 2018 22:13:30 -0400 From: Tom Lane To: Laurenz Albe cc: Seamus Abshere , pgsql-general@postgresql.org Subject: Re: Is my text_pattern_ops index working for a LIKE prefix search with column reference? In-reply-to: References: <1535036221.3796184.1483854296.64E1B683@webmail.messagingengine.com> Comments: In-reply-to Laurenz Albe message dated "Fri, 24 Aug 2018 02:46:38 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26279.1535076810.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 23 Aug 2018 22:13:30 -0400 Message-ID: <26280.1535076810@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Laurenz Albe writes: > Seamus Abshere wrote: >> I created an index with text_pattern_ops because I want fast prefix sea= rch [1] [2]. >> ...but I don't think it's working when I use a column reference || '%'.= .. > An index can only be used for expressions like > > and you have a column refrence on the right side. "constant" is a bit too strong here, but it definitely can't be "expression using another column from the same table". It has to be an expression that will hold stable throughout a scan of the table you wish to index. regards, tom lane