-- test/sql/regex_groups_index.sql -- -- Patterns core's regex accepts must work through the index, with the same -- rows as a sequential scan, and with trigrams where the pattern has them. -- -- pg_tre's own pattern parser exists only to find trigrams for the index; -- the recheck's engine (core regex for ~, TRE for %~~) decides matches. -- Before 4.3.1 that parser rejected patterns it did not know -- lazy -- quantifiers ('x*?'), empty alternatives ('(|a)'), director prefixes -- ('***='), '{,3}' -- with "pg_tre: invalid regex pattern:" and an empty -- message, only on the index path. Lookarounds and '(?:...)' were scanned -- with no trigrams at all. Reported by depesz for '(?<=e.)aa[bc]c[b-d]'. -- Now: '(?:X)' is a group, a lookaround stands in for an optional -- character, a lazy quantifier is its greedy twin, and anything else the -- parser cannot read is scanned lossily and left to the recheck. CREATE EXTENSION IF NOT EXISTS pg_tre; psql:test/sql/regex_groups_index.sql:17: NOTICE: extension "pg_tre" already exists, skipping CREATE EXTENSION SET client_min_messages = warning; SET DROP TABLE IF EXISTS rgx; DROP TABLE CREATE TABLE rgx (id int, s text); CREATE TABLE INSERT INTO rgx VALUES (1, 'xe.aacbz'), (2, 'xf.aacbz'), (3, 'the nation'), (4, 'motion'), (5, 'fooxbar'), (6, 'foo bar'), (7, '{,3}'), (8, 'a{,3}b'), (9, 'tion'), (10, 'ab'), (11, 'abc)def'), (12, 'xx(ab'), (13, '***=lit'), (14, 'aaa'), (15, 'nation-wide'); INSERT 0 15 INSERT INTO rgx SELECT g, 'filler ' || g FROM generate_series(100, 1100) g; INSERT 0 1001 CREATE INDEX rgx_tre ON rgx USING tre (s); CREATE INDEX ANALYZE rgx; ANALYZE CREATE TEMP TABLE pats (p text); CREATE TABLE INSERT INTO pats VALUES ('(?<=e.)aa[bc]c[b-d]'), ('(?<=e\.)aac'), ('(?