Index used incorrectly with regular expressions on 7.4.6 - Mailing list pgsql-hackers

From Antti Salmela
Subject Index used incorrectly with regular expressions on 7.4.6
Date
Msg-id vab182-r7r.ln1@asalmela.iki.fi
Whole thread Raw
Responses Re: Index used incorrectly with regular expressions on 7.4.6
List pgsql-hackers
Index is used incorrectly if constant part of the string ends with \d,
probably also with other escapes.

foo=# explain select count(*) from loc where url ~ '^http://www\\.7-eleven\\.com/newsroom/articles\\.asp\\?p=\\d+';
QUERYPLAN
 

Aggregate  (cost=3.46..3.46 rows=1 width=0)   ->  Index Scan using url_index on loc  (cost=0.00..3.46 rows=1 width=0)
        Index Cond: ((url >=     'http://www.7-eleven.com/newsroom/articles.asp?p=d'::text) AND     (url <
'http://www.7-eleven.com/newsroom/articles.asp?p=e'::text))             Filter: (url ~
'^http://www\\.7-eleven\\.com/newsroom/articles\\.asp\\?p=\\d+'::text)         (4 rows)
 
foo=# select count(*) from loc where url ~ '^http://www\\.7-eleven\\.com/newsroom/articles\\.asp\\?p=\\d+';count-------
0
 
(1 row)

foo=# set enable_indexscan = off;
SET
foo=# explain select count(*) from loc where url ~ '^http://www\\.7-eleven\\.com/newsroom/articles\\.asp\\?p=\\d+';
                                   QUERY PLANAggregate  (cost=3056.41..3056.41 rows=1 width=0)   ->  Seq Scan on loc
(cost=0.00..3056.40rows=1 width=0)            Filter: (url ~
'^http://www\\.7-eleven\\.com/newsroom/articles\\.asp\\?p=\\d+'::text)    (3 rows)     
 
foo=# select count(*) from loc where url ~'^http://www\\.7-eleven\\.com/newsroom/articles\\.asp\\?p=\\d+';count-------
281
 
(1 row)

-- 
Antti Salmela



pgsql-hackers by date:

Previous
From: Manfred Spraul
Date:
Subject: Re: libpq and psql not on same page about SIGPIPE
Next
From: Neil Conway
Date:
Subject: Re: New compile warnings for inheritance