I have a table product
product_id | desciption
============================================================
322919 | text {add}185{/add} text
322920 | text {add}184{/add} text {add}185{/add} text
322921 | text {add}185{/add} text {add}187{/add} text
sql query with like is very slow
SELECT product_id, desciption
FROM product
WHERE LOWER(desciption) like '%{add}185{/add}%'
> Time: 340,159s
I only need an index to search for {add}185{/add} expressions. i.e. need to make an index for this table
SELECT product_id, regexp_matches (desciption, '(\{add\}\d+\{\/add\})', 'g')
FROM product
returns:
product_id | regexp_matches
================================================================================
322919 | {"{add}185{/add}"}
322920 | {"{add}184{/add}"}
322920 | {"{add}185{/add}"}
322921 | {"{add}185{/add}"}
322921 | {"{add}187{/add}"}
- Which is better to create an index for data sampling?
- Which is better to use the expression in "WHERE"?