Re: Reverse btree indexes

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Zach Aysan <zachaysan(at)gmail(dot)com>, Pg Docs <pgsql-docs(at)lists(dot)postgresql(dot)org>
Subject: Re: Reverse btree indexes
Date: 2021-06-23 16:08:56
Message-ID: 202106231608.7x3hv4bi4dv7@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On 2021-Jun-22, David G. Johnston wrote:

> On Tue, Jun 22, 2021 at 2:28 PM Zach Aysan <zachaysan(at)gmail(dot)com> 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)

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Peter Eisentraut 2021-06-24 11:20:07 Re: Has the Update savepoint example outlived its usefulness?
Previous Message Tom Lane 2021-06-23 16:07:29 Re: Incorrect Syntax in Function Syntax diagram