Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XMvPr-0006Zd-1I for pgsql-performance@arkaria.postgresql.org; Thu, 28 Aug 2014 08:50:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XMvPq-0001BT-G6 for pgsql-performance@arkaria.postgresql.org; Thu, 28 Aug 2014 08:50:46 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XMvPp-00018v-23 for pgsql-performance@postgresql.org; Thu, 28 Aug 2014 08:50:45 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XMvPm-0004yH-3V for pgsql-performance@postgresql.org; Thu, 28 Aug 2014 08:50:43 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1XMvPk-0006IH-Hb for pgsql-performance@postgresql.org; Thu, 28 Aug 2014 01:50:40 -0700 Date: Thu, 28 Aug 2014 01:50:40 -0700 (PDT) From: gmb To: pgsql-performance@postgresql.org Message-ID: <1409215840535-5816702.post@n5.nabble.com> Subject: Performance issue: index not used on GROUP BY... MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Hi all I have the following table with 10+ million records: create table ddetail ( ddet_id serial, co_id integer, client_id integer, doc_no varchar, line_id integer, batch_no integer, amount NUMERIC , ..., constraint PRIMAR KEY ( co_id , client_id , doc_no , line_id, ddet_id ) ) ; When doing the following query on this table, performance is really slow: SELECT co_id , client_id , doc_no , line_id , sum( amount ) FROM ddetail GROUP BY co_id , client_id , doc_no , line_id It seems as if the planner is not using the PRIMARY KEY as index which was my assumption. Can somebody please confirm whether aggregate functions such as GROUP BY should use indexes ? Thanks in advance gmb -- View this message in context: http://postgresql.1045698.n5.nabble.com/Performance-issue-index-not-used-on-GROUP-BY-tp5816702.html Sent from the PostgreSQL - performance mailing list archive at Nabble.com. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance