Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 50049650309 for ; Wed, 12 Nov 2008 15:45:03 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 96488-04 for ; Wed, 12 Nov 2008 15:44:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from smtp-out.neti.ee (smtp-out.neti.ee [194.126.126.37]) by mail.postgresql.org (Postfix) with ESMTP id 38CAC650225 for ; Wed, 12 Nov 2008 15:44:55 -0400 (AST) Received: from localhost (localhost [127.0.0.1]) by MXR-13.estpak.ee (Postfix) with ESMTP id 571F62B5FD; Wed, 12 Nov 2008 21:44:51 +0200 (EET) X-Virus-Scanned: amavisd-new at !change-mydomain-variable!.example.com Received: from smtp-out.neti.ee ([127.0.0.1]) by localhost (MXR-1.estpak.ee [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id afP+F8agSwDT; Wed, 12 Nov 2008 21:44:44 +0200 (EET) Received: from Relayhost1.neti.ee (Relayhost1 [88.196.174.141]) by MXR-13.estpak.ee (Postfix) with ESMTP id 0DFDD2B8C6; Wed, 12 Nov 2008 21:44:44 +0200 (EET) X-SMTP-Auth-NETI-Businesmail: no Received: from andrusnotebook (unknown [195.50.198.194]) by Relayhost1.neti.ee (Postfix) with SMTP id E21152A4D3B; Wed, 12 Nov 2008 21:44:44 +0200 (EET) Message-ID: <498EDF1308A1409E9CE994C83A345BA3@andrusnotebook> From: "Andrus" To: "Vladimir Sitnikov" Cc: References: <1d709ecc0811120928n3c183df5kb7b7d50dee6f73ed@mail.gmail.com> <1d709ecc0811121126k4558db13m88c959188c3a9c0f@mail.gmail.com> In-Reply-To: <1d709ecc0811121126k4558db13m88c959188c3a9c0f@mail.gmail.com> Subject: Re: Increasing select max(datecol) from bilkaib where datecol<=date'2008-11-01' and (cr='00' or db='00') speed Date: Wed, 12 Nov 2008 21:44:38 +0200 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Windows Mail 6.0.6001.18000 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6001.18049 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=STOX_REPLY_TYPE=0.001 X-Spam-Level: X-Archive-Number: 200811/106 X-Sequence-Number: 31837 Vladimir, >I am afraid PostgreSQL is not smart enough to rewrite query with "or" into >two separate index scans. There is no way to improve the query >significantly without rewriting it. >Note: for this case indices on (datecol), (cr) and (db) are not very >helpful. Thank you very much. I added you indexes to db and re-write query. Now it runs fast. Andrus.