Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 3F2A99FB1BF for ; Sat, 27 Jan 2007 13:28:18 -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 75208-05 for ; Sat, 27 Jan 2007 13:28:13 -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 166049F9F0A for ; Sat, 27 Jan 2007 13:28:12 -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 l0RHSBY0006889; Sat, 27 Jan 2007 12:28:11 -0500 (EST) To: Carlos Moreno cc: pgsql-performance@postgresql.org Subject: Re: Seqscan/Indexscan still a known issue? In-reply-to: <45BB873C.4000304@mochima.com> References: <45BAB682.6060709@mochima.com> <45BB214E.3090907@fuzzy.cz> <45BB873C.4000304@mochima.com> Comments: In-reply-to Carlos Moreno message dated "Sat, 27 Jan 2007 12:09:16 -0500" Date: Sat, 27 Jan 2007 12:28:11 -0500 Message-ID: <6888.1169918891@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200701/385 X-Sequence-Number: 22986 Carlos Moreno writes: > But I think the problem is that this particular table had not been > vacuum analyzed after having inserted the 20000 records (the > query planner was giving me seq. scan when the table had about > a dozen records --- and seq. scan was, indeed, 10 times faster; > as a test, to make sure that the query planner would do the right > thing when the amount of records was high, I inserted 20000 > records, and tried again --- now the seq. scan was 100 times > slower, but it was still chosen (at that point was that I did a > search through the archives and then posted the question). > But now, after reading the replies, I did a vacuum analyze for > this table, and now the query planner is choosing the Index > scan. One reason you might consider updating is that newer versions check the physical table size instead of unconditionally believing pg_class.relpages/reltuples. Thus, they're much less likely to get fooled when a table has grown substantially since it was last vacuumed or analyzed. regards, tom lane