Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id C6ECDB5DCD4 for ; Wed, 14 Sep 2011 11:15:06 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 88553-09 for ; Wed, 14 Sep 2011 14:15:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from elizabeth.gransy.com (ns2.gransy.com [89.187.132.100]) by mail.postgresql.org (Postfix) with ESMTP id AE6C0B5DC61 for ; Wed, 14 Sep 2011 11:14:56 -0300 (ADT) Received: from sq.gransy.com (localhost [127.0.0.1]) by elizabeth.gransy.com (Postfix) with ESMTP id 2A26E15E42EF; Wed, 14 Sep 2011 16:14:55 +0200 (CEST) Received: from 85.162.207.69 (SquirrelMail authenticated user tv@fuzzy.cz) by sq.gransy.com with HTTP; Wed, 14 Sep 2011 16:14:55 +0200 Message-ID: <0ac4fa43876e63ec84515656f233960f.squirrel@sq.gransy.com> In-Reply-To: <1316005753084-4802699.post@n5.nabble.com> References: <1316004607207-4802634.post@n5.nabble.com> <1316005753084-4802699.post@n5.nabble.com> Date: Wed, 14 Sep 2011 16:14:55 +0200 Subject: Re: cannot use multicolumn index From: "Tomas Vondra" To: "MirrorX" Cc: pgsql-performance@postgresql.org User-Agent: SquirrelMail/1.4.21 MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201109/214 X-Sequence-Number: 44990 On 14 Září 2011, 15:09, MirrorX wrote: > here is the explain analyze output-> > server=# explain analyze select count(*) from temp_by_hour where xid > 100 > and xdate > now() - interval '1 week'; > QUERY > PLAN > --------------------------------------------------------------------------------------------------------------------------------------------------- > Aggregate (cost=29359311.58..29359311.59 rows=1 width=0) (actual > time=2728061.589..2728061.590 rows=1 loops=1) > -> Seq Scan on temp_by_hour (cost=0.00..29345234.14 rows=5630975 > width=0) (actual time=560446.661..2726838.501 rows=5760724 loops=1) > Filter: ((xid > 100) AND (xdate > (now() - '7 days'::interval))) > Total runtime: 2728063.170 ms Sorry, but with this amount of information, no one can actually help. - What is the problem, i.e. what behaviour you expect? - How much data is the table? - What portion of it matches the conditions? - What is the index definition? My bet is the conditions are not selective enough and the index scan would be less effective than reading the whole table. Try to disable seqscan or modify the cost variables so that the index scan is used and see if it's faster or not. Tomas