我有一个桌子产品
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
Run Code Online (Sandbox Code Playgroud)
使用like进行sql查询非常慢
SELECT product_id, desciption
FROM product
WHERE LOWER(desciption) like '%{add}185{/add}%'
> Time: 340,159s
Run Code Online (Sandbox Code Playgroud)
我只需要一个索引来搜索 {add}185{/add} 表达式。即需要为此表建立索引
SELECT product_id, regexp_matches (desciption, '(\{add\}\d+\{\/add\})', 'g')
FROM product
Run Code Online (Sandbox Code Playgroud)
返回:
product_id | regexp_matches
================================================================================
322919 | {"{add}185{/add}"}
322920 | {"{add}184{/add}"}
322920 | {"{add}185{/add}"}
322921 | {"{add}185{/add}"}
322921 | {"{add}187{/add}"}
Run Code Online (Sandbox Code Playgroud)