bug of pg_trgm? - Mailing list pgsql-hackers

From Fujii Masao
Subject bug of pg_trgm?
Date
Msg-id CAHGQGwGxgUiqyid2yjfZwZmMzn9BZmVjmHua2ZqPvU2KR=5SqA@mail.gmail.com
Whole thread Raw
Responses Re: bug of pg_trgm?
List pgsql-hackers
Hi,

When I used pg_trgm, I encountered the problem that the search result of
SeqScan was the different from that of BitmapScan even if the search
keyword was the same. Is this a bug? Here is the test case:

---------------------------
CREATE EXTENSION pg_trgm;
CREATE TABLE tbl (col text);
CREATE INDEX idx ON tbl USING gin (col gin_trgm_ops);
INSERT INTO tbl VALUES ('abc'), ('ab c');

SET enable_seqscan TO off;
SET enable_bitmapscan TO on;
SELECT * FROM tbl WHERE col LIKE E'%\\c%';
 col
------
 ab c
(1 row)

SET enable_seqscan TO on;
SET enable_bitmapscan TO off;
SELECT * FROM tbl WHERE col LIKE E'%\\c%';
 col
------
 abc
 ab c
(2 rows)
---------------------------

The cause is ISTM that pg_trgm wrongly ignores the heading wildcard
character (i.e., %) when an escape (i.e., \\) follows the wildcard character.
Attached patch fixes this.

The patch fixes another problem: pg_trgm wrongly ignores the backslash \\
following the escape, i.e., \\\\. This problem might be harmless when
KEEPONLYALNUM is enabled because any characters other than
alphabets and digits are ignored. But, when KEEPONLYALNUM is disabled,
\\\\ should be interpreted as a backslash character itself, but
pg_trgm does not.

Regards,

--
Fujii Masao

Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: WIP: pg_pretty_query
Next
From: Andrew Dunstan
Date:
Subject: Re: WIP: pg_pretty_query