【发布时间】:2026-01-15 01:50:01
【问题描述】:
我是 Postgres 的新手,并试图弄清楚如何在 where 子句中使用“Like”来提高计数查询的性能。
select count(*)
from master_data
where name ilike '%<userInput>%';
估计值我什至没问题。我用谷歌搜索了几个链接,发现我们可以通过使用以下查询快速获得整个表的计数。
SELECT reltuples AS approximate_row_count FROM pg_class WHERE relname = '<TableName>';
但是对于类似条件的计数,我仍然无法弄清楚。 请建议。以下是我已经提到的链接。
https://wiki.postgresql.org/wiki/Count_estimate
https://www.citusdata.com/blog/2016/10/12/count-performance/#dup_counts_estimated_filtered
Postgres 版本 - 9.5.4
【问题讨论】:
-
%val%无法使用索引。你能在%val or val%? or useIN`或=的一端使用%吗?关于另一个问题的更多信息:dba.stackexchange.com/questions/10694/…
标签: sql postgresql count