【发布时间】:2020-06-10 01:18:45
【问题描述】:
我有一张桌子产品
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
like的sql查询很慢
SELECT product_id, desciption
FROM product
WHERE LOWER(desciption) like '%{add}185{/add}%'
> Time: 340,159s
我只需要一个索引来搜索 {add}185{/add} 表达式。 即需要为这个表建立一个索引
SELECT product_id, regexp_matches (desciption, '(\{add\}\d+\{\/add\})', 'g')
FROM product
返回:
product_id | regexp_matches
================================================================================
322919 | {"{add}185{/add}"}
322920 | {"{add}184{/add}"}
322920 | {"{add}185{/add}"}
322921 | {"{add}185{/add}"}
322921 | {"{add}187{/add}"}
- 为数据采样创建索引哪个更好?
- 在“WHERE”中使用哪个表达式更好?
【问题讨论】:
-
您应该查看全文索引或 GIN 索引。
标签: sql postgresql indexing