Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id A43962E3189 for ; Sat, 31 May 2008 01:24:54 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 55885-01-3 for ; Sat, 31 May 2008 01:24:43 -0300 (ADT) Received: from mx3.hub.org (mx3.hub.org [206.223.169.73]) by developer.postgresql.org (Postfix) with ESMTP id 8EE282E012D for ; Fri, 30 May 2008 08:02:47 -0300 (ADT) X-Greylist: delayed 00:33:06.047243 by SQLgrey-1.7.5 Received: from dc.baikal.ru (dc.baikal.ru [212.176.3.237]) by mx3.hub.org (Postfix) with ESMTP id BCF4037BAE6 for ; Fri, 30 May 2008 08:02:46 -0300 (ADT) Received: from it319k5.dc-local (it319k5.dc-local [10.0.4.75]) (authenticated bits=0) by dc.baikal.ru (8.13.8/8.13.8) with ESMTP id m4UB2e1f018904 for ; Fri, 30 May 2008 20:02:40 +0900 Message-ID: <483FDED1.1070503@dc.baikal.ru> Date: Fri, 30 May 2008 20:02:41 +0900 From: Vlad Arkhipov User-Agent: Thunderbird 2.0.0.0 (X11/20070326) MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Statistics issue Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV version 0.93, clamav-milter version 0.93 on dc.baikal.ru X-Virus-Status: Clean X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=AWL=0.000 X-Spam-Level: X-Archive-Number: 200805/378 X-Sequence-Number: 30346 I have a big table that is used in many queries. Most used index is created on date field. Number of records in this table when date field is saturday is about 5 times smaller than other days, on sunday this number is always 0. Statistics target is 1000. Many queries have problems when condition on this table looks like "d between '2007-05-12' and '2007-05-12'" (saturday). EXPLAIN ANALYZE SELECT * FROM i WHERE d BETWEEN '2007-05-12' AND '2007-05-12' Index Scan using i_d on i (cost=0.00..2.39 rows=1 width=402) (actual time=0.053..4.284 rows=1721 loops=1) Index Cond: ((d >= '2007-05-12'::date) AND (d <= '2007-05-12'::date)) Total runtime: 6.645 ms EXPLAIN ANALYZE SELECT * FROM i WHERE d = '2007-05-12' Index Scan using i_d on i (cost=0.00..38.97 rows=1572 width=402) (actual time=0.044..4.250 rows=1721 loops=1) Index Cond: (d = '2007-05-12'::date) Total runtime: 6.619 ms Is there a way to solve this problem?