Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TKujG-0001ie-HV for pgsql-performance@postgresql.org; Sun, 07 Oct 2012 17:33:26 +0000 Received: from forward3.mail.yandex.net ([2a02:6b8:0:602::3]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TKujD-00021x-0P for pgsql-performance@postgresql.org; Sun, 07 Oct 2012 17:33:26 +0000 Received: from web11d.yandex.ru (web11d.yandex.ru [77.88.47.156]) by forward3.mail.yandex.net (Yandex) with ESMTP id 71F77B412A3 for ; Sun, 7 Oct 2012 21:33:20 +0400 (MSK) Received: from 127.0.0.1 (localhost.localdomain [127.0.0.1]) by web11d.yandex.ru (Yandex) with ESMTP id 2F21F60200ED; Sun, 7 Oct 2012 21:33:20 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1349631200; bh=iPQ5K0/dkXaTeAyuA8stQDuVCc+oRyQ1y6gtZ9IKics=; h=From:To:Subject:MIME-Version:Message-Id:Date: Content-Transfer-Encoding:Content-Type; b=XjRVmaZvx5DdTakqSLSc/md88lzHdPUSrIs9O9IugAWF5LA0gNzEXj4SVA6rY6669 aom9QnJUIYqKefdyLGoYR3vThZSEnmffC48vqWYsAhNy+lSfXum6mD3XwM5Pt4QqQq iJmEgnPDkm9azNXCjzOeS3sGCfrgZQkl3CfAJakI= Received: from [188.168.10.0] ([188.168.10.0]) by web11d.yandex.ru with HTTP; Sun, 07 Oct 2012 21:33:19 +0400 From: Korisk To: pgsql-performance@postgresql.org Subject: hash aggregation speedup MIME-Version: 1.0 Message-Id: <739641349631199@web11d.yandex.ru> Date: Sun, 07 Oct 2012 21:33:19 +0400 X-Mailer: Yamail [ http://yandex.ru ] 5.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201210/37 X-Sequence-Number: 47996 I have table: create table hashcheck(id serial, name varchar, value varchar); and query: hashaggr=# explain analyse verbose select name, count(name) as cnt from hashcheck group by name order by name desc; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=471979.50..471985.40 rows=2362 width=9) (actual time=19642.938..19643.184 rows=4001 loops=1) Output: name, (count(name)) Sort Key: hashcheck.name Sort Method: quicksort Memory: 343kB -> HashAggregate (cost=471823.53..471847.15 rows=2362 width=9) (actual time=19632.256..19632.995 rows=4001 loops=1) Output: name, count(name) -> Seq Scan on public.hashcheck (cost=0.00..363494.69 rows=21665769 width=9) (actual time=49.552..11674.170 rows=23103672 loops=1) Output: id, name, value Total runtime: 19643.497 ms (9 rows) without indexes. Indexes don't speedup the query much For hash Total runtime: 17678.225 ms For btree Total runtime: 14188.484 ms I'm don't know how to use Gin and gist this way. So the question is there any way to speed up the "group by" query? Or may be there does exists any other way to count histogram? Thank you. PS: hashaggr=# select version(); version ------------------------------------------------------------------------------------------------------------- PostgreSQL 9.1.6 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2), 64-bit