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 1fsxIh-0003Pt-1u for pgsql-general@arkaria.postgresql.org; Thu, 23 Aug 2018 21:37:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fsxIc-0000Rk-RU for pgsql-general@arkaria.postgresql.org; Thu, 23 Aug 2018 21:37:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fsr2t-000771-LG for pgsql-general@lists.postgresql.org; Thu, 23 Aug 2018 14:57:11 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fsr2m-0001cS-5j for pgsql-general@postgresql.org; Thu, 23 Aug 2018 14:57:11 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 96A2D21AC8 for ; Thu, 23 Aug 2018 10:57:01 -0400 (EDT) Received: from web2 ([10.202.2.212]) by compute2.internal (MEProxy); Thu, 23 Aug 2018 10:57:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=SESyChqdbr3UEmMpd8zbVBMKJUSqz 23/ZW1/slXGnw8=; b=s0DXGnXQl0UOAYXn/ihT79egXsOK0Ng2FtGC50m00pOSl LWxxXNvW4w4JRAiKjKWnumMscQXIsgeAdOJaL9rmph78gIrFnF2c8O9/dsTisDUr Xb9Ye9u89JQBQiFo3+I+RluK3c85DcQ83PeEtvinHfnDa43S86AOvLVtdCsdVX3S u9c91ULcGRAelWPY2NLXfJIVWNo4FZyIozX6DJAFuIcVXsws0sGD1SBsndQK8v3I b3Wp8eQPtoKvwsVHIy3dTBHwE8NFGK/Qi8jQmXeylkjqKL1aSRfbZl1+I+FK9Sjs FuxqUP0ItnEBtq4RdqGNsjzpLEso4q8/HLzd9kIeg== X-ME-Proxy: X-ME-Sender: Received: by mailuser.nyi.internal (Postfix, from userid 99) id 34B68621E6; Thu, 23 Aug 2018 10:57:01 -0400 (EDT) Message-Id: <1535036221.3796184.1483854296.64E1B683@webmail.messagingengine.com> From: Seamus Abshere To: pgsql-general@postgresql.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" X-Mailer: MessagingEngine.com Webmail Interface - ajax-7b72137a Date: Thu, 23 Aug 2018 11:57:01 -0300 Subject: Is my text_pattern_ops index working for a LIKE prefix search with column reference? List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk hi, I created an index with text_pattern_ops because I want fast prefix search [1] [2]. CREATE INDEX ON mytable USING BTREE (state, city, address text_pattern_ops); (Note it's composite - I'm looking for prefixes on the address part only.) I can see that it "works" (purely uses the index) for prefix searches without column references: # explain select 1 from mytable where state = 'x' and city = 'x' and address like 'asd%'; QUERY PLAN -- Index Only Scan using mytable_state_city_house_number_and_s_idx1 on mytable (cost=0.41..4.44 rows=1 width=4) Index Cond: ((state = 'x'::text) AND (city = 'x'::text) AND (address ~>=~ 'asd'::text) AND (address ~<~ 'ase'::text)) Filter: (address ~~ 'asd%'::text) (3 rows) ...but I don't think it's working when I use a column reference || '%'... I say that because "address" no longer appears in the "Index Cond": # explain select (select 1 from mytable where state = 'x' and city = 'x' and address like generate_series.generate_series::text || '%') t2 from generate_series(0, 10); QUERY PLAN -- Function Scan on generate_series (cost=0.00..4455.00 rows=1000 width=4) SubPlan 1 -> Index Only Scan using mytable_state_city_house_number_and_s_idx1 on mytable (cost=0.41..4.44 rows=1 width=4) Index Cond: ((state = 'x'::text) AND (city = 'x'::text)) Filter: (address ~~ ((generate_series.generate_series)::text || '%'::text)) (5 rows) Any advice? I'm on 10.3. Also, has this changed between 9.6 and 10.3? And... maybe I'm asking the wrong question, how can I do a fast search on state, city, address prefix? Thanks, Seamus [1] http://blog.cleverelephant.ca/2016/08/pgsql-text-pattern-ops.html [2] https://blog.2ndquadrant.com/text-search-strategies-in-postgresql/