我有一个包含超过 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_name,last_name和email。
我可以做些什么来提高此查询的性能?
postgresql performance index full-text-search postgresql-performance