我想搜索兩個不同表中的 2 列,一個是name,另一個是description,分別是型別string和text。
當我在互聯網上看到各種博客/東西時,我真的很困惑找到最快的獲取資料的方法。
每個表中有 100K 行。
到目前為止我所做的:我tsvector為包含描述的表創建了一個列,并用GIN. 但是我對如何為 name 列執行此操作感到困惑?
我不能使用,ilike '%{keyword}%'因為它不使用索引。
是否也可以使用全文搜索name(字串型別),或者對我的情況最好的方法是什么?
提前致謝
select *
from
((select name as "customId", id as aid
from accounts
where name ilike '%cust%' limit 10)
union all
(select t2."customId", null
from t2
where t2.tsv @@ to_tsquery('cust') limit 10)
) e2
uj5u.com熱心網友回復:
您搜索使用的想法UNION ALL很好。
為了加速子字串搜索,您可以使用三元組索引:
CREATE EXTENSION IF NOT EXISTS pg_trgm;
CREATE INDEX ON accounts USING gin (name gin_trgm_ops);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/366504.html
標籤:sql PostgreSQL的 表现 全文搜索
上一篇:根據資料框中的另一列計算出現次數
