X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 2869B9FA509 for ; Fri, 5 May 2006 11:47:04 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 52348-01 for ; Fri, 5 May 2006 11:46:52 -0300 (ADT) X-Greylist: delayed 00:06:39.021932 by SQLgrey- Received: from listonosz.d1.pl (listonosz.d1.pl [212.244.177.134]) by postgresql.org (Postfix) with SMTP id 41DF29FA372 for ; Fri, 5 May 2006 11:46:51 -0300 (ADT) Received: (qmail 14688 invoked by uid 11185); 5 May 2006 14:40:17 -0000 Received: from 212.244.177.188 by listonosz (envelope-from , uid 129) with qmail Received: from hq.d1.pl (HELO tekno) (w.strzelczyk@212.244.177.188) by 0 with SMTP; 5 May 2006 14:40:17 -0000 From: Witold Strzelczyk Organization: Digital One sp. z o.o. To: pgsql-performance@postgresql.org Subject: slow variable against int?? Date: Fri, 5 May 2006 16:46:43 +0200 User-Agent: KMail/1.9.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200605051646.44060.w.strzelczyk@digitalone.pl> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/207 X-Sequence-Number: 18994 I have a question about my function. I must get user rating by game result. This isn't probably a perfect solution but I have one question about select into inGameRating count(game_result)+1 from users where game_result > inRow.game_result; This query in function results in about 1100 ms. inRow.game_result is a integer 2984 And now if I replace inRow.game_result with integer select into inGameRating count(game_result)+1 from users where game_result > 2984; query results in about 100 ms There is probably a reason for this but can you tell me about it because I can't fine one My function: create or replace function ttt_result(int,int) returns setof tparent_result language plpgsql volatile as $$ declare inOffset alias for $1; inLimit alias for $2; inRow tparent_result%rowtype; inGameResult int := -1; inGameRating int := -1; begin for inRow in select email,wynik_gra from konkurs_uzytkownik order by wynik_gra desc limit inLimit offset inOffset loop if inGameResult < 0 then -- only for first iteration /* this is fast ~100 ms select into inGameRating count(game_result)+1 from users where game_result > 2984; */ /* even if inRow.game_result = 2984 this is very slow ~ 1100 ms! select into inGameRating count(game_result)+1 from users where game_result > inRow.game_result; */ inGameResult := inRow.game_result; end if; if inGameResult > inRow.game_result then inGameRating := inGameRating + 1; end if; inRow.game_rating := inGameRating; inGameResult := inRow.game_result; return next inRow; end loop; return; end; $$; -- Witold Strzelczyk witek.strzelczyk@gmail.com