sql - postgres 以类似条件计数

标签 sql postgresql count

我是 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/

相关文章:

sql - MySQL存储过程动态修改表名

MySQL语句-从一组中选择最大值

c# - 使用 LINQ 计算嵌套的导航表行

java - 比例大小无效。不能小于零

sql - 访问 Azure 自动备份

mysql - MariaDB 比较两个表中的数字计数

windows - 无法获取在 Windows 版本上运行的示例 C 函数

postgresql - 如何从应用程序级别设置 postgres 查询执行超时?

postgresql - Heroku 上的 Alembic/Flask-migrate 迁移运行但不创建表

sql - 将计数追加为表列