Is there any way to replace like condition in postgresql?

六月ゝ 毕业季﹏ 提交于 2019-12-24 15:05:03

问题


I am having the following query in my code. It takes a minute to get the data due to to the like condition. If you have any way to replace it or speed up the retrieve time, Please let me know.

select id, url
from activitylog
where resource = 'jobs'
  and (method = 'saveTechStatus')
  and (url like '%/jobs/saveTechStatus/81924/%')
order by timestamp desc;

回答1:


You could use a trigram index:

CREATE EXTENSION pg_trgm;
CREATE INDEX ON activitylog USING gin (url gin_trgm_ops);

This may take a lot of space, but it can speed up this LIKE condition.



来源:https://stackoverflow.com/questions/55136522/is-there-any-way-to-replace-like-condition-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!