简体   繁体   English

状况类似的postgres计数

[英]postgres count with like condition

I am new to Postgres and trying to figure out how can i improve performance of count query with 'Like' in where clause. 我是Postgres的新手,并试图弄清楚如何在where子句中使用“赞”来提高计数查询的性能。

    select    count(*) 
    from master_data 
    where name ilike '%<userInput>%';

I am even fine with estimated value.I googled few links and found out we can quickly get a count of entire table by using below query. 我什至可以估计值。我在几个链接上搜索了一下,发现我们可以通过使用以下查询来快速获取整个表的数量。

 SELECT reltuples AS approximate_row_count FROM pg_class WHERE relname = '<TableName>'; 

However for count with like condition i am still not able to figure out. 但是对于类似条件的计数我仍然无法弄清楚。 Please suggest.Below are the links which i referred already. 请提出建议。以下是我已经提到的链接。

https://wiki.postgresql.org/wiki/Count_estimate https://wiki.postgresql.org/wiki/Count_estimate

https://www.citusdata.com/blog/2016/10/12/count-performance/#dup_counts_estimated_filtered https://www.citusdata.com/blog/2016/10/12/count-performance/#dup_counts_estimated_filtered

Postgres Version - 9.5.4 Postgres版本-9.5.4

Do you must use LIKE? 您必须使用LIKE吗? Maybe it's possible to make something with IN? 也许可以用IN做点什么? http://www.postgresqltutorial.com/postgresql-in/ http://www.postgresqltutorial.com/postgresql-in/

You might be interested in a trigram index. 您可能对Trigram索引感兴趣。 This can specifically handle like with wildcards. 这可以like通配符like专门处理。 You can start with the documentation . 您可以从文档开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM