Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 489479FA0B7 for ; Thu, 4 Jan 2007 23:04:13 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 27355-02 for ; Thu, 4 Jan 2007 23:04:07 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id F29A19FA131 for ; Thu, 4 Jan 2007 23:04:06 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id l05345wR008871; Thu, 4 Jan 2007 22:04:05 -0500 (EST) To: "Dave Dutcher" cc: pgsql-performance@postgresql.org Subject: Re: Slow Query on Postgres 8.2 In-reply-to: <007901c7306b$fd1d2c90$8300a8c0@tridecap.com> References: <007901c7306b$fd1d2c90$8300a8c0@tridecap.com> Comments: In-reply-to "Dave Dutcher" message dated "Thu, 04 Jan 2007 19:51:16 -0600" Date: Thu, 04 Jan 2007 22:04:05 -0500 Message-ID: <8870.1167966245@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/66 X-Sequence-Number: 22667 "Dave Dutcher" writes: > Here is the table definition. Thanks. [ fools around with it for awhile... ] I think this is already fixed for 8.2.1. Note the costs of the two related index scans: 8.2.0: -> Bitmap Index Scan on om_transaction_om_transaction_index (cost=0.00..7421.67 rows=488 width=0) (actual time=3411.227..3411.227 rows=0 loops=1) Index Cond: ((as_of_date > '2006-12-04'::date) AND (as_of_date <= '2006-12-05'::date) AND ((strategy_id)::text = ANY (('{BASKET1,BASKET2,BASKET3,BASKET4,BASKET5,BASKET6,BASKET7,BASKET8,BASKET9,BASKET10,BASKET11}'::character varying[])::text[])) AND ((owner_trader_id)::text = ANY (('{dave,sam,bob,tad,tim,harry,frank,bart,lisa,homer,marge,maggie,apu,milhouse,"disco stu"}'::character varying[])::text[])) AND (cf_account_id = ANY ('{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,29}'::integer[]))) 8.1.2: -> Bitmap Index Scan on om_transaction_om_transaction_index (cost=0.00..101.69 rows=5949 width=0) (actual time=3.419..3.419 rows=7967 loops=1) Index Cond: ((as_of_date > '2006-12-04'::date) AND (as_of_date <= '2006-12-05'::date)) 8.1.2 returns a lot more rows but spends a lot less time doing it. The reason is that using all those =ANY clauses as index quals is *expensive* --- they actually trigger multiple scans of the index. 8.2.0 is underestimating their cost. We fixed that a couple weeks ago (after some reports from Arjen van der Meijden) and I can't actually get 8.2 branch tip to produce a plan like what you show. Please try it again when 8.2.1 comes out (Monday) and we'll see if there's any more tweaking needed. BTW, it's interesting to note that the plan 8.1.2 produces is pretty obviously bogus in itself ... why do only the first two arms of the BitmapOr use as_of_date conditions? We fixed some sillinesses in the bitmap scan planning later in the 8.1 series, so I think you'd find that 8.1.latest does this differently. regards, tom lane