X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id CBCDED79BC for ; Fri, 26 Aug 2005 12:17:02 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 16234-03 for ; Fri, 26 Aug 2005 15:16:59 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id A3115D7108 for ; Fri, 26 Aug 2005 12:16:55 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j7QFGtGH009249; Fri, 26 Aug 2005 11:16:55 -0400 (EDT) To: stange@rentec.com Cc: pgsql-performance@postgresql.org Subject: Re: difference in plan between 8.0 and 8.1? In-reply-to: <430F2AF3.1080704@rentec.com> References: <430F2AF3.1080704@rentec.com> Comments: In-reply-to Alan Stange message dated "Fri, 26 Aug 2005 10:45:07 -0400" Date: Fri, 26 Aug 2005 11:16:55 -0400 Message-ID: <9248.1125069415@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 required=5 tests=[AWL=0.006] X-Spam-Level: X-Archive-Number: 200508/440 X-Sequence-Number: 14187 Alan Stange writes: > Unique (cost=2717137.08..2771407.21 rows=10854026 width=8) > -> Sort (cost=2717137.08..2744272.14 rows=10854026 width=8) > Sort Key: timeseriesid > -> Bitmap Heap Scan on tbltimeseries > (cost=48714.09..1331000.42 rows=10854026 width=8) > Recheck Cond: (timeseriesid > 0) > -> Bitmap Index Scan on idx_timeseris > (cost=0.00..48714.09 rows=10854026 width=0) > Index Cond: (timeseriesid > 0) > (7 rows) > I'm hoping someone can explain the new query plan (as I'm not sure I > understand what it is doing). The index scan is reading the index to find out which heap tuple IDs (TIDs) the index says meet the condition. It returns a bitmap of the tuple locations (actually, an array of per-page bitmaps). The heap scan goes and fetches the tuples from the table, working in TID order to avoid re-reading the same page many times, as can happen for ordinary index scans. Since the result isn't sorted, we have to do a sort to get it into the correct order for the Unique step. Because it avoids random access to the heap, this plan can be a lot faster than a regular index scan. I'm not sure at all that 8.1 is doing good relative cost estimation yet, though. It would be interesting to see EXPLAIN ANALYZE results for both ways. (You can use enable_bitmapscan and enable_indexscan to force the planner to pick the plan it thinks is slower.) regards, tom lane