From oracle-l-bounce@freelists.org Wed Apr 13 08:01:56 2005 Return-Path: Received: from air891.startdedicated.com (root@localhost) by orafaq.com (8.12.10/8.12.10) with ESMTP id j3DD1ube012435 for ; Wed, 13 Apr 2005 08:01:56 -0500 X-ClientAddr: 206.53.239.180 Received: from turing.freelists.org (freelists-180.iquest.net [206.53.239.180]) by air891.startdedicated.com (8.12.10/8.12.10) with ESMTP id j3DD1uem012430 for ; Wed, 13 Apr 2005 08:01:56 -0500 Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 003C795B0D; Wed, 13 Apr 2005 06:59:44 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 24926-03; Wed, 13 Apr 2005 06:59:44 -0500 (EST) Received: from turing (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 7D74695F30; Wed, 13 Apr 2005 06:59:44 -0500 (EST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=GI3+zrqrIG5mFQ+Bt60jc0XL4n6ETDX3RypH35MJVzjJhNiWCH3Ag0Q74mI98Rh9WkPhB9JLKaVjjVViPtpcflLnlQo8u1oNj2LAmf6aKXbO9l3s/aXia1CUrQkFecQAirxTWdSB4domvpQD2N6+6OaGmSar8U49otpsjPva8xc= Message-ID: <6e49b6d005041304576429fbc1@mail.gmail.com> Date: Wed, 13 Apr 2005 14:57:54 +0300 From: Gints Plivna To: Edgar Chupit Subject: Re: Lag function problem was: Never ending activity in temp file Cc: oracle-l@freelists.org In-Reply-To: Mime-Version: 1.0 Content-type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Content-Disposition: inline References: <6e49b6d0050413011347a4ab5b@mail.gmail.com> X-archive-position: 18420 X-ecartis-version: Ecartis v1.0.0 Sender: oracle-l-bounce@freelists.org Errors-To: oracle-l-bounce@freelists.org X-original-sender: gints.plivna@gmail.com Precedence: normal Reply-To: gints.plivna@gmail.com X-list: oracle-l X-Virus-Scanned: by amavisd-new-20030616-p9 (Debian) at avenirtech.net X-Spam-Checker-Version: SpamAssassin 2.60 (1.212-2003-09-23-exp) on air891.startdedicated.com X-Spam-Status: No, hits=0.0 required=5.0 tests=none autolearn=ham version=2.60 X-Spam-Level: > For your particular query you can tune it, by specifying partition > clause, and thus limiting the size of the analytic window.=20 I'll try partition clause. And I tried a bit also lead function, appeared it hadn't such problems (of course I can somehow order everything vice versa and try lead). > But I guess what you are really want to ask is: if for particular ID > there is more than one row, give me the code of the first row, else > give me value of current row. this is oversimplified example just to show performance problems. The real problem generally was, to count all codes for particular persons, but in a following manner: if person has code 'LVA' then count it and only it. if person hasn't code 'LVA' then count all other codes particular person ha= s. So to avoid exists clause, self join or something similar I tried to partition source table (actually join from many tables) by person id and order by code in a manner that 'LVA' always comes first. Then for each person I'll look back and see if this is new person, then I count the code. If this is the same person as in previous row, then I'll look back for this person first code, if it is 'LVA' then I don't count code, else count it. In this report I had to simply count codes, in other reports I'll have to join them to other dimensions and count somehow even more complex for example by address or sex. And I see that here is the real power of analytic functions, especially if they worked as I imagined :))) > Like Tom Kyte says "Tune the question, not the query".=20 Of course that's true. -- http://www.freelists.org/webpage/oracle-l