X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 6C6EB11F662D for ; Thu, 30 Mar 2006 08:31:42 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 38355-06 for ; Thu, 30 Mar 2006 08:31:41 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from cassarossa.samfundet.no (cassarossa.samfundet.no [129.241.93.19]) by postgresql.org (Postfix) with ESMTP id 19E1611F662E for ; Thu, 30 Mar 2006 08:31:40 -0400 (AST) Received: from trofast.ipv6.sesse.net ([2001:700:300:dc03:20e:cff:fe36:a766] helo=trofast.sesse.net) by cassarossa.samfundet.no with esmtp (Exim 4.50) id 1FOwJP-0006KB-H9; Thu, 30 Mar 2006 14:31:39 +0200 Received: from sesse by trofast.sesse.net with local (Exim 3.36 #1 (Debian)) id 1FOwJK-0003Ul-00; Thu, 30 Mar 2006 14:31:34 +0200 Date: Thu, 30 Mar 2006 14:31:34 +0200 From: "Steinar H. Gunderson" To: Peter Eisentraut Cc: pgsql-performance@postgresql.org Subject: Re: Index scan startup time Message-ID: <20060330123134.GA13408@uio.no> Mail-Followup-To: Peter Eisentraut , pgsql-performance@postgresql.org References: <200603301359.11038.peter_e@gmx.net> <20060330120206.GA13075@uio.no> <200603301423.54510.peter_e@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <200603301423.54510.peter_e@gmx.net> X-Operating-System: Linux 2.6.14.3 on a x86_64 X-Message-Flag: Outlook? --> http://www.mozilla.org/products/thunderbird/ User-Agent: Mutt/1.5.11+cvs20060126 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.1 required=5 tests=[AWL=0.100] X-Spam-Score: 0.1 X-Spam-Level: X-Archive-Number: 200603/612 X-Sequence-Number: 18049 On Thu, Mar 30, 2006 at 02:23:53PM +0200, Peter Eisentraut wrote: >>> EXPLAIN ANALYZE select activity_id from activity where state in (10000, >>> 10001) order by activity_id limit 100; >>> >>> QUERY PLAN >>> >>> Limit (cost=0.00..622.72 rows=100 width=8) (actual >>> time=207356.054..207356.876 rows=100 loops=1) >>> -> Index Scan using activity_pk on activity (cost=0.00..40717259.91 >>> rows=6538650 width=8) (actual time=207356.050..207356.722 rows=100 >>> loops=1) Filter: ((state = 10000) OR (state = 10001)) >>> Total runtime: 207357.000 ms >>> >>> The table has seen VACUUM FULL and REINDEX before this. >> The index scan is by activity_id, not by state. Do you have an index on >> state at all? > There is an index on state as well but the column is not selective enough. Well, it's logical enough; it scans along activity_id until it finds one with state=10000 or state=10001. You obviously have a _lot_ of records with low activity_id and state none of these two, so Postgres needs to scan all those records before it founds 100 it can output. This is the “startup cost” you're seeing. /* Steinar */ -- Homepage: http://www.sesse.net/