1、DISTINCT response time is fast without being added qis3_dp2=# SELECT COUNT(*) AS CHECKCARNUM FROM QIS_CARPASSEDSTATION A WHERE 1=1 AND A.SSTATIONCD = 'VQ3_LYG' AND A.SLINENO IN ( '1F' , '2F' , '3F' ) AND A.DWORKDATE >= TO_DATE('2017-02-11','YYYY-MM-DD') AND A.DWORKDATE <= TO_DATE('2019-03-11','YYYY-MM-DD'); checkcarnum ------------- 2142215 (1 row) *Time: 2237.970 ms (00:02.238)* qis3_dp2=# 2、 Adding a DISTINCT response time was very slow qis3_dp2=# SELECT COUNT(DISTINCT SVIN) AS CHECKCARNUM FROM QIS_CARPASSEDSTATION A WHERE 1=1 AND A.SSTATIONCD = 'VQ3_LYG' AND A.SLINENO IN ( '1F' , '2F' , '3F' ) AND A.DWORKDATE >= TO_DATE('2017-02-11','YYYY-MM-DD') AND A.DWORKDATE <= TO_DATE('2019-03-11','YYYY-MM-DD'); checkcarnum ------------- 1071367 (1 row) *Time: 38979.246 ms (00:38.979)* -- Sent from: http://www.postgresql-archive.org/PostgreSQL-performance-f2050081.html