Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: Querying 2 Values Form 1 Column in DBIx::Class

by erix (Parson)
on Jan 28, 2018 at 00:27 UTC ( #1208004=note: print w/replies, xml ) Need Help??


in reply to Re^3: Querying 2 Values Form 1 Column in DBIx::Class
in thread Querying 2 Values Form 1 Column in DBIx::Class

... to avoid the LIKE operator where INSTR is sufficient

Some databases do even better: in postgres there is the option to index on regular expressions (or any string) via the pg_trgm contrib extension.

Its disadvantage is huge index size but the gain can be enormous, as indeed in this, the OP's example:

-- table t is 112 MB, 1 million rows. The index is 190 MB (!) -- all queries measured on second run (to avoid uninteresting cold cac +he slowness) -- no index: SELECT * FROM t WHERE name like '%Franklin%' and name like '%Linsey%'; Time: 118.004 ms SELECT * FROM t WHERE position('Franklin' in name)>0 AND position('Lin +sey' in name)>0; Time: 444.716 ms create index t_trgm_re_idx on t using gin (name gin_trgm_ops); -- with index: SELECT * FROM t WHERE name like '%Franklin%' and name like '%Linsey%' + ; Time: 1.582 ms -- postgres specific regex-search syntax with '~' SELECT * FROM t WHERE name ~ 'Franklin' and name ~ 'Linsey'; Time: 1.895 ms

The latter syntax has the added advantage that one can use regex like 'Frankl[iy]n' (it will use the trgm index as well).

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1208004]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2019-11-19 21:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (96 votes). Check out past polls.

    Notices?