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 1lw5R7-0004kM-Cw for pgsql-docs@arkaria.postgresql.org; Wed, 23 Jun 2021 16:09:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lw5R6-00088y-Bm for pgsql-docs@arkaria.postgresql.org; Wed, 23 Jun 2021 16:09:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lw5R5-00084b-Jl for pgsql-docs@lists.postgresql.org; Wed, 23 Jun 2021 16:09:08 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lw5R2-0001AB-1e for pgsql-docs@lists.postgresql.org; Wed, 23 Jun 2021 16:09:07 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 5AFBE146A; Wed, 23 Jun 2021 12:09:00 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 23 Jun 2021 12:09:00 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=xz/PSOMbKui+Gj66HAE3R02xvC+ToT9kfMGsqKeQyrI=; b=c5s2wEq/ q3ZYvw+4s43f6Qksr2Ms3yDdYJb/mg3gWHFamjXjralZZeUS3sF4NmH1sD/noCbK JnbmToVYdOfVbYRtYKghM2nAbFhO6vQZ7YrM68T9Hf0sHJyEofFt8rNO2lScROXr 8Ujq4kkd0ZxRM/k/F6m0Y6G4C1OlCSLLW9Ejy6e8VamuvngQxOfmruTx86ER22V1 Z28pAZHeX0AIYiBoVRsEB0/t6nFA9hAE/Xq9YgXm/ufdf+WMkeLpXtorlEYYX6gc D+9U2He5Ms+gbeITDfeTCCj0sHdAbxtH4S0JeUsR4h9gGzd2K1vkT4YC6jpWclgd zJt1cgBmaNPlYg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeegfedgleelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpeelvdfgffevvdeiueekkeejvddtfeetueeijeettdfgheel feeifeeuteeludevueenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 23 Jun 2021 12:08:59 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 6FAED2A0ADA; Wed, 23 Jun 2021 12:08:56 -0400 (-04) Date: Wed, 23 Jun 2021 12:08:56 -0400 From: Alvaro Herrera To: "David G. Johnston" Cc: Zach Aysan , Pg Docs Subject: Re: Reverse btree indexes Message-ID: <202106231608.7x3hv4bi4dv7@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2021-Jun-22, David G. Johnston wrote: > On Tue, Jun 22, 2021 at 2:28 PM Zach Aysan wrote: > >> for example, col LIKE 'foo%' or col ~ '^foo', but not col LIKE '%bar', > >> which would require a reversed index on the field. To use the reversed > >> index, query with reverse(col) like reverse('%bar'). > > > This type of commentary isn't usually something we include in the > documentation...and I'm not too keen on "reversed index" as a phrase > regardless. Maybe we can add it as a parenthical comment. Something like : The optimizer can also use a B-tree index for queries involving the : pattern matching operators LIKE and ~ if the pattern is a constant and : is anchored to the beginning of the string — for example, col LIKE : 'foo%' or col ~ '^foo', but not col LIKE '%bar' (it is possible to : use an expressional index to support queries such as the latter; see : Section 11.7). However, [...] Then add an example in 11.7 Indexes on Expressions below the two existing examples. I think this is a noteworthy use of expressional indexes; I've had to explain the reverse() idea a couple of times. -- Álvaro Herrera 39°49'30"S 73°17'W "The eagle never lost so much time, as when he submitted to learn of the crow." (William Blake)