X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C85A43A3F1D for ; Thu, 20 Jan 2005 10:14:52 +0000 (GMT) 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 68547-09 for ; Thu, 20 Jan 2005 10:14:41 +0000 (GMT) Received: from mailout10.sul.t-online.com (mailout10.sul.t-online.com [194.25.134.21]) by svr1.postgresql.org (Postfix) with ESMTP id D45593A444B for ; Thu, 20 Jan 2005 10:14:42 +0000 (GMT) Received: from fwd06.aul.t-online.de by mailout10.sul.t-online.com with smtp id 1CrZKq-0001Iu-03; Thu, 20 Jan 2005 11:14:40 +0100 Received: from jupiter.home.lan (ZY8QCyZGrexmqr3DrnVn8RIdrIaceHP-3eiq6zix1vKHr5jJgiRo8h@[217.86.71.171]) by fmrl06.sul.t-online.com with esmtp id 1CrZKg-0vCzr60; Thu, 20 Jan 2005 11:14:30 +0100 Received: from [192.168.20.1] (jupiter.home.lan [192.168.20.1]) by jupiter.home.lan (Postfix) with ESMTP id 38EC61A1F98 for ; Thu, 20 Jan 2005 11:14:29 +0100 (CET) Mime-Version: 1.0 (Apple Message framework v619) Content-Transfer-Encoding: 7bit Message-Id: <11D72EC4-6ACC-11D9-A12E-000A957B8C6E@users.sourceforge.net> Content-Type: text/plain; charset=US-ASCII; format=flowed To: pgsql-performance@postgresql.org From: Bernd Heller Subject: column without pg_stats entry?! Date: Thu, 20 Jan 2005 11:14:28 +0100 X-Mailer: Apple Mail (2.619) X-ID: ZY8QCyZGrexmqr3DrnVn8RIdrIaceHP-3eiq6zix1vKHr5jJgiRo8h@t-dialin.net X-TOI-MSGID: 84888618-89ec-442d-a461-10492af040ea X-Virus-Scanned: by amavisd-new at hub.org X-Archive-Number: 200501/261 X-Sequence-Number: 9951 Hello everyone, I'm having a problem with some of my tables and I'm not sure if postgres' behaviour is maybe even a bug. I'm (still) using 8.0rc5 at present. I have a table that contains among other columns one of the sort: purge_date timestamp most records will have this field set to NULL, at present all of them really. the table has about 100k row right now. in regular intervals I'm doing some cleanup on this table using a query like: delete from mytable where purge_date is not null and purge_date < current_date And I have created these btree indexes: create index on mytable (purge_date); create index on mytable (purge_date) where purge_date is not null; my problem is that the planner always chooses a seq scan over an index scan. only when I set enable_seqscan to false does it use an index scan. The costs of both plans are extremely different, with the index scan being 5-10 times more expensive than the seq scan, which is obviously not true given that all rows have this column set to NULL. I wondered why the planner was making such bad assumptions about the number of rows to find and had a look at pg_stats. and there was the surprise: there is no entry in pg_stats for that column at all!! I can only suspect that this has to do with the column being all null. I tried to change a few records to a not-null value, but re-ANALYZE didn't catch them apparently. Is this desired behaviour for analyze? Can I change it somehow? If not, is there a better way to accomplish what I'm trying? I'm not to keen on disabling seqscan for that query explicitly. It's a simple enough query and the planner should be able to find the right plan without help - and I'm sure it would if it had stats about it. Any help appreciated. Bernd