Skip to content

Commit 8ef31af

Browse files
committed
Copy edit text for new indexing support
1 parent 64f5c88 commit 8ef31af

3 files changed

Lines changed: 25 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@ All notable changes to this project will be documented in this file. It uses the
1414
* Added `re2_version()`, which returns the full semantic version. This is
1515
the same value visible in `pg_get_loaded_modules()`, but available in
1616
Postgres versions prior to 18, and without having to load re2 first.
17-
* Index support.
18-
* `WHERE re2match(col, '^order_2025')` a pattern starting with `^` and a
19-
fixed prefix now reads only matching range of an existing b-tree index.
20-
See [Index Support](doc/re2.md#index-support).
17+
* Added Index support, avoiding table scans for patterns that can use an
18+
index:
19+
* A pattern starting with `^` and a fixed prefix, such as `WHERE
20+
re2match(col, '^order_2025')`, now reads the matching range of an
21+
existing b-tree index. See [Index Support](doc/re2.md#index-support).
2122
* Added `@~` match operator (same as `re2match`) and `gin_re2_ops`
2223
operator class. `CREATE INDEX ... USING gin (col gin_re2_ops)` lets
2324
`WHERE col @~ pattern` only visit rows containing required trigrams.
24-
* Row-count estimates for `re2match` and `@~` filters with a constant
25-
pattern now come from testing the pattern against column statistics
26-
instead of a fixed guess, so the planner picks better plans around
27-
such filters.
25+
* Row-count estimates for `re2match` and `@~` now come from testing
26+
patterns against column statistics for patterns containing a constant
27+
pattern. In such cases this improves cost estimation over the default
28+
fixed guess, allowing the planner to pick better plans.
2829

2930
### 📔 Notes
3031

benchmark/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ Data is 10000 rows of:
2525
Index scans
2626
-----------
2727

28-
`re2` also speeds up `re2match` through two index mechanisms (see
29-
[Index Support]). This compares each against the equivalent PostgreSQL
30-
index scan over a separate 100000-row table.
28+
`re2` also speeds up `re2match` through two index mechanisms (see [Index
29+
Support]). These queries compare each against the equivalent PostgreSQL index
30+
scan over a separate 100000-row table.
3131

3232
| Mechanism | re2 | postgres |
3333
| ------------------- | ---------------------------- | ---------------------------- |

doc/re2.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -505,15 +505,16 @@ SELECT * FROM logs WHERE msg @~ 'connection (refused|timed out)';
505505
```
506506

507507
`@~` and `re2match(text, text)` match identically, produce the same row
508-
estimates, and both use the b-tree ranges below. Only `@~` can use a GIN
509-
index, since Postgres ties GIN operator classes to operators, not functions.
508+
estimates, and both use the b-tree ranges [described
509+
below](#b-tree-range-from-an-anchored-prefix). Only `@~` can use a GIN index,
510+
since Postgres ties GIN operator classes to operators, not functions.
510511

511512
## Index Support
512513

513514
Without an index, every RE2 filter reads whole table. Two mechanisms below let
514515
applicable patterns visit only rows that could match, then recheck the exact
515-
match on each candidate: results never change, only how fast they arrive, with
516-
one known GIN exception noted below.
516+
match on each candidate: results never change, only how quickly they arrive,
517+
with one known GIN exception noted below.
517518

518519
Matching, indexed or not, compares raw UTF-8 bytes without Unicode
519520
normalization: a pattern with a composed character (`é` as one code point)
@@ -522,11 +523,11 @@ accent). Pattern and haystack must agree on normalization form.
522523

523524
### B-tree range from an anchored prefix
524525

525-
When pattern is a constant starting with `^` and a fixed prefix, `re2match` and
526-
`@~` filters read only the index range covering that prefix. No query or index
527-
change needed, provided the index orders bytewise: a `text_pattern_ops` index,
528-
or a default b-tree whose collation sorts like `C` (`C`, `POSIX`, builtin `C`
529-
and `C.UTF8`).
526+
For a constant pattern starting with `^` and a fixed prefix, `re2match` and
527+
`@~` read only the index range covering that prefix. This feature requires no
528+
query or index change, provided the index orders bytewise, such as a
529+
`text_pattern_ops` index or a default b-tree whose collation sorts like `C`
530+
(`C`, `POSIX`, builtin `C` and `C.UTF8`).
530531

531532
```sql
532533
CREATE INDEX ON logs (msg text_pattern_ops);
@@ -544,8 +545,9 @@ to the plan the query would otherwise get.
544545
`gin_re2_ops` indexes three-character sequences (trigrams) of each value.
545546
A `@~` query reduces its pattern to literal text every match needs.
546547

547-
Below example finds `connection ` plus `refused` or `timed out` and visits
548-
only rows containing necessary trigrams, rechecking full pattern on each.
548+
This example finds `connection ` plus `refused` or `timed out` via the
549+
`gin_re2_ops` GIN index and visits only rows containing necessary trigrams,
550+
rechecking the full pattern on each:
549551

550552
```sql
551553
CREATE INDEX ON logs USING gin (msg gin_re2_ops);

0 commit comments

Comments
 (0)