public inbox for [email protected]help / color / mirror / Atom feed
Reverse btree indexes 3+ messages / 3 participants [nested] [flat]
* Reverse btree indexes @ 2021-06-22 18:46 Zach Aysan <[email protected]> 0 siblings, 1 reply; 3+ messages in thread From: Zach Aysan @ 2021-06-22 18:46 UTC (permalink / raw) To: [email protected] Hey there! Thanks for putting together such wonderful documentation. I have a small suggestion for improvement. *Page:* https://www.postgresql.org/docs/13/indexes-types.html *Existing language:* for example, col LIKE 'foo%' or col ~ '^foo', but not col LIKE '%bar'. *Desired improvement:* for example, col LIKE 'foo%' or col ~ '^foo', but not col LIKE '%bar', > which would require a reversed index on the field. Postgres will > automatically use the reverse index for LIKE '%bar' *Or if it doesn't:* > 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'). I hope you all have a great day! Zach ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Reverse btree indexes @ 2021-06-22 22:51 David G. Johnston <[email protected]> parent: Zach Aysan <[email protected]> 0 siblings, 1 reply; 3+ messages in thread From: David G. Johnston @ 2021-06-22 22:51 UTC (permalink / raw) To: Zach Aysan <[email protected]>; +Cc: Pg Docs <[email protected]> On Tue, Jun 22, 2021 at 2:28 PM Zach Aysan <[email protected]> wrote: > *Desired improvement:* > > for example, col LIKE 'foo%' or col ~ '^foo', but not col LIKE '%bar', >> which would require a reversed index on the field. Postgres will >> automatically use the reverse index for LIKE '%bar' > > > *Or if it doesn't:* > It doesn't, otherwise the documentation wouldn't need to point out: but not col LIKE '%bar' ... > >> 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. David J. ^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Reverse btree indexes @ 2021-06-23 16:08 Alvaro Herrera <[email protected]> parent: David G. Johnston <[email protected]> 0 siblings, 0 replies; 3+ messages in thread From: Alvaro Herrera @ 2021-06-23 16:08 UTC (permalink / raw) To: David G. Johnston <[email protected]>; +Cc: Zach Aysan <[email protected]>; Pg Docs <[email protected]> On 2021-Jun-22, David G. Johnston wrote: > On Tue, Jun 22, 2021 at 2:28 PM Zach Aysan <[email protected]> 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) ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2021-06-23 16:08 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2021-06-22 18:46 Reverse btree indexes Zach Aysan <[email protected]> 2021-06-22 22:51 ` David G. Johnston <[email protected]> 2021-06-23 16:08 ` Alvaro Herrera <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox