Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id CEFF364FD42 for ; Wed, 12 Nov 2008 14:36:18 -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 81457-04 for ; Wed, 12 Nov 2008 14:36:10 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id B5B9D64FE15 for ; Wed, 12 Nov 2008 14:36:10 -0400 (AST) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.1/8.14.1) with ESMTP id mACIa86N077567 for ; Wed, 12 Nov 2008 14:36:08 -0400 (AST) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.1/8.14.1/Submit) id mACI6xWR047488 for pgsql-performance@postgresql.org; Wed, 12 Nov 2008 14:06:59 -0400 (AST) (envelope-from news) From: "Andrus" X-Newsgroups: pgsql.performance 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 20:06:47 +0200 Organization: Hub.Org Networking Services Lines: 24 Message-ID: References: <1d709ecc0811120928n3c183df5kb7b7d50dee6f73ed@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org In-Reply-To: X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Windows Mail 6.0.6001.18000 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6001.18049 To: pgsql-performance@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200811/103 X-Sequence-Number: 31834 Matthew, Thank you. bilkaib table contains GL transactions for every day. 00 records are initial balance records and they appear only in start of year or start of month. They may present or may be not present for some month if initial balance is not calculated yet. If 00 records are present, usuallly there are lot of them for single date for db and cr columns. This query finds initial balance date befeore given date. bilkaib table contains several year transactions so it is large. >Alternatively if you create an index on (cr, bilkaib) and one on (db, >bilkaib) then you will be able to use other values in the query too. I'm sorry I do'nt understand this. What does the (cr, bilkaib) syntax mean? Should I create two functions indexes and re-write query as Vladimir suggests or is there better appoach ? Andrus.