一品网
  • 首页

sql优化-使用exists代替distinct


and c_ajbh in (select distinct c_ajbh from db_zxzhld.t_zhld_zbajxx where n_dbzt = 1 and c_zblx = '1003' and c_gy = '2550' )
改写为:
and exists (select c_ajbh from db_zxzhld.t_zhld_zbajxx where n_dbzt = 1 and c_zblx = '1003' and c_gy = '2550' )

一旦满足条件则立刻返回。所以使用exists的时候子查询可以直接去掉distinct。从执行计划来看使用exists可以消除分组,提高效率。

PostgreSQL

相关


【Gerrit】Gerrit+Postgresql安装方式的数据备份

PostgreSQL数据库常用SQL命令示例

使用pgcli工具连接postgreSQL数据库服务

postgresql-shared_buffers

前沿分享|阿里云资深技术专家 魏闯先:AnalyticDB PostgreSQL年度新版本发布

Centos7系统-postgresql+etcd+patroni+haproxy+keepalived高可用集群部署

Centos7系统-postgresql+etcd+patroni+haproxy+keepalived高可用集群部署

【TPC-DS】trino+S3+hive+postgresql性能测试----生成简单数据验证环境(四)

【TPC-DS】trino+S3+hive+postgresql性能测试----生成简单数据验证环境(四)

PostgreSql查看当前表的主外键关系

postgresql-用户登录数据库

harbor-db 启动时报initdb: directory "/var/lib/postgresql/data" exists but is not

标签

一品网 冀ICP备14022925号-6