我是 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
最佳答案
一定要用LIKE吗? 也许可以用 IN 做点什么? http://www.postgresqltutorial.com/postgresql-in/
关于sql - postgres 以类似条件计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44421121/