Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TMWe2-0002BC-FZ for pgsql-performance@postgresql.org; Fri, 12 Oct 2012 04:14:42 +0000 Received: from forward3h.mail.yandex.net ([2a02:6b8:0:f05::3]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TMWe0-0004bQ-4m for pgsql-performance@postgresql.org; Fri, 12 Oct 2012 04:14:42 +0000 Received: from web27h.yandex.ru (web27h.yandex.ru [84.201.187.161]) by forward3h.mail.yandex.net (Yandex) with ESMTP id D70B11361DB2; Fri, 12 Oct 2012 08:14:38 +0400 (MSK) Received: from 127.0.0.1 (localhost.localdomain [127.0.0.1]) by web27h.yandex.ru (Yandex) with ESMTP id 75EBC64082D7; Fri, 12 Oct 2012 08:14:38 +0400 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1350015278; bh=+c5ZGSy5uyvMaSfs+ERc0GAg12yGibjrbEFh4tTQk1M=; h=From:To:Cc:In-Reply-To:References:Subject:MIME-Version:Message-Id: Date:Content-Transfer-Encoding:Content-Type; b=foEOX63tZ0aBLu7zafeoXOr7YcLx7aqye5wChi65XiblguMB+Vp2Cj5NcQRTHbnHo X2X2N30p8SSq+lTNBAesAyFOU9xRd+NwaalV4OZRvpHg3HjeciMRAsdUP3fWk7p/Xi Hw3F/X5jpbI5v3tjC3zmu6f3HZkx6KDjTtxGGTWg= Received: from [188.168.10.0] ([188.168.10.0]) by web27h.yandex.ru with HTTP; Fri, 12 Oct 2012 08:14:38 +0400 From: Korisk To: Sergey Konoplev Cc: Craig Ringer , "pgsql-performance@postgresql.org" In-Reply-To: References: <118871349885342@web16f.yandex.ru> <323831349928808@web5g.yandex.ru> <50764D55.2060401@ringerc.id.au> <53981349968513@web6f.yandex.ru> <246351350014151@web25e.yandex.ru> Subject: Re: hash aggregation MIME-Version: 1.0 Message-Id: <270381350015278@web27h.yandex.ru> Date: Fri, 12 Oct 2012 08:14:38 +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/159 X-Sequence-Number: 48118 Strange situation. After indexscan enabling the cost is seriously decreased. hashes=# set enable_bitmapscan=on; SET hashes=# explain analyse verbose select name, count(name) as cnt from hashcheck group by name order by name desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------ GroupAggregate (cost=10000000000.00..10000596612.97 rows=200 width=32) (actual time=0.187..7424.799 rows=4001 loops=1) Output: name, count(name) -> Index Only Scan using hashcheck_name_rev_idx on public.hashcheck (cost=10000000000.00..10000466660.96 rows=25990002 width=32) (act ual time=0.166..3698.776 rows=25990002 loops=1) Output: name Heap Fetches: 0 Total runtime: 7425.403 ms (6 rows) hashes=# set enable_indexscan=on; SET hashes=# explain analyse verbose select name, count(name) as cnt from hashcheck group by name order by name desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------ --------------------------------- GroupAggregate (cost=0.00..596612.97 rows=200 width=32) (actual time=0.148..7339.115 rows=4001 loops=1) Output: name, count(name) -> Index Only Scan using hashcheck_name_rev_idx on public.hashcheck (cost=0.00..466660.96 rows=25990002 width=32) (actual time=0.129. .3653.848 rows=25990002 loops=1) Output: name Heap Fetches: 0 Total runtime: 7339.592 ms (6 rows) hashes=# set enable_seqscan=on; SET hashes=# explain analyse verbose select name, count(name) as cnt from hashcheck group by name order by name desc; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------------------ ----- Sort (cost=565411.67..565412.17 rows=200 width=32) (actual time=21746.799..21747.026 rows=4001 loops=1) Output: name, (count(name)) Sort Key: hashcheck.name Sort Method: quicksort Memory: 315kB -> HashAggregate (cost=565402.03..565404.03 rows=200 width=32) (actual time=21731.551..21733.277 rows=4001 loops=1) Output: name, count(name) -> Seq Scan on public.hashcheck (cost=0.00..435452.02 rows=25990002 width=32) (actual time=29.431..13383.812 rows=25990002 loop s=1) Output: id, name, value Total runtime: 21747.356 ms (9 rows)