问题
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