小编Vic*_*tor的帖子

在多个文本字段上使用模式匹配进行更快的查询

我有一个包含超过 20M 元组的 Postgres 表:

first_name | last_name | email
-------------------------------------------
bat        | man       | batman@wayne.com
arya       | vidal     | foo@email.com
max        | joe       | bar@email.com
Run Code Online (Sandbox Code Playgroud)

要过滤我正在使用的记录:

SELECT *
  FROM people
WHERE (first_name || '' || last_name) ILIKE '%bat%man%' OR 
    first_name ILIKE '%bat%man%'  OR  
    last_name ILIKE '%bat%man%'   OR
    email ILIKE '%bat%man%'
    LIMIT 25 OFFSET 0
Run Code Online (Sandbox Code Playgroud)

即使使用索引,搜索也需要将近一分钟才能返回结果。
有索引的(first_name || '' || last_name)first_namelast_nameemail

我可以做些什么来提高此查询的性能?

postgresql performance index full-text-search postgresql-performance

12
推荐指数
1
解决办法
1万
查看次数