Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1adsNv-0005aE-JX for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Mar 2016 04:39:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1adsNv-0003u6-5U for pgsql-bugs@arkaria.postgresql.org; Thu, 10 Mar 2016 04:39:39 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1adsIf-0002wE-Ke for pgsql-bugs@postgresql.org; Thu, 10 Mar 2016 04:34:13 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1adsIW-00021B-KU for pgsql-bugs@postgresql.org; Thu, 10 Mar 2016 04:34:11 +0000 MIME-Version: 1.0 Subject: BUG #14011: select count(distinct column) does not utilizes indices to improve performance To: pgsql-bugs@postgresql.org From: gtakahashi@palantir.com Date: Thu, 10 Mar 2016 04:33:27 +0000 Message-ID: <20160310043327.8903.60230@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 14011 Logged by: Glen Takahashi Email address: gtakahashi@palantir.com PostgreSQL version: 9.3.6 Operating system: Red Hat Enterprise Linux 6.7 Description: Doing a select count(distinct column) does not utilize indices and takes a very long time to compute. For example Create table test_table (number integer); Create index on test_table (number); Insert into test_table (number) select generate_series(1,100000); (I did this ~500 times to replicate the scale of data we have) Select count(distinct number) from test_table; Count 100000 Time: 63419.600ms Select count(1) from (select distinct number from test_table) a; Count 100000 Time: 10743.186 ms -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs