有什么办法可以替换PostgreSQL中的类似条件? [英] Is there any way to replace like condition in postgresql?

查看:70
本文介绍了有什么办法可以替换PostgreSQL中的类似条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有以下查询。由于 like 条件,需要花费一分钟来获取数据。如果您有任何替换它或加快检索时间的方法,请告诉我。

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;


推荐答案

您可以使用三字母组合索引:

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.

这篇关于有什么办法可以替换PostgreSQL中的类似条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆