X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id B8D3AD1C9C4 for ; Thu, 1 Apr 2004 08:07:55 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 06498-01 for ; Thu, 1 Apr 2004 04:07:54 -0400 (AST) Received: from bonito.ulb.ac.be (mailhost.ulb.ac.be [164.15.59.220]) by svr1.postgresql.org (Postfix) with ESMTP id 13B55D1B55E for ; Thu, 1 Apr 2004 04:07:52 -0400 (AST) Received: from mach.vub.ac.be (mach.ulb.ac.be [164.15.128.8]) by bonito.ulb.ac.be (8.8.8/3.17.1.ap (resu)) id KAA18660; Thu, 1 Apr 2004 10:05:25 +0200 (MEST) for Received: from olivier.amaze.ulb.ac.be (ucmbsgi10.ulb.ac.be [164.15.109.34]) by mach.vub.ac.be (Postfix) with ESMTP id E3CB12303; Thu, 1 Apr 2004 10:07:51 +0200 (CEST) Date: Thu, 01 Apr 2004 10:07:52 +0300 To: "Tom Lane" Subject: Re: Is it normal that functions are so much faster than inline queries Cc: pgsql-sql@postgresql.org References: <5019.1080747200@sss.pgh.pa.us> From: "Olivier Hubaut" Organization: SCMBB Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: In-Reply-To: <5019.1080747200@sss.pgh.pa.us> User-Agent: Opera M2/7.50 (MacPPC, build 1701) X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/1 X-Sequence-Number: 17376 On Wed, 31 Mar 2004 10:33:20 -0500, Tom Lane wrote: > "Olivier Hubaut" writes: >> When I want to execute this set of queries in a function: >> ... >> It takes only 2 seconds. > >> But when I tried to do it directly in the psql term (replacing the $1 >> value with the same used in the function call), I'm obliged to kill the >> second query after 10 minutes because it's still runnning! > > You're presumably getting different plans in the two cases. Usually > we hear complaints about the function case being slower, because the > planner has less information when it has to work with a parameter > instead of a constant. In this case it seems the stupider plan is being > chosen with a constant :-(. You have not shown enough information to > tell why, but I'm wondering about datatype mismatch preventing an index > from being used. What is the declared datatype of the $1 parameter, and > does it match what will be assumed for the unadorned constant? > > regards, tom lane > Thank you for your response I'll try to give enough information this time - the columns 'batch' used in the join is a char(50) in the two table - the columns 'id' and 'new_value' also used in the join are both char(64) - the argument passed to the function is a string The first table (oly.amaze_log_database_object) have more or less 40,000 rows that are corresponding to the first part of the 'where' clause (batch=$1) on a total amount of 41,000 The second one (oly.amaze_log_object) have more or less 20,000 rows on a total amount of 21,000 that should match with the join condition. They are no index and I tried to put some on the couples (batch, id) and (batch, new_value) and/or the (batch) columns, without more success. Hope that's enough. For the moment, we planned to upgrade to Pg 7.4, hoping this will resolve the problem... Regards, Olivier Hubaut -- Downloading signature ... 99% *CRC FAILED* signature aborted