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 07D15D1C9C8 for ; Wed, 31 Mar 2004 13:28:20 +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 06503-07 for ; Wed, 31 Mar 2004 09:28:12 -0400 (AST) Received: from bonito.ulb.ac.be (bonito.ulb.ac.be [164.15.59.220]) by svr1.postgresql.org (Postfix) with ESMTP id 9C5C6D1E85C for ; Wed, 31 Mar 2004 09:28:08 -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 PAA05721; Wed, 31 Mar 2004 15:25:46 +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 14CA222FF for ; Wed, 31 Mar 2004 15:28:11 +0200 (CEST) To: pgsql-sql@postgresql.org Subject: Is it normal that functions are so much faster than inline queries Date: Wed, 31 Mar 2004 15:28:10 +0300 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: User-Agent: Opera M2/7.50 (MacPPC, build 1701) X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/272 X-Sequence-Number: 17371 I'm doing some test on our PgSQL 7.3.4 and I can't believe what I see: When I want to execute this set of queries in a function: DELETE FROM oly.amaze_log_report WHERE batch = $1 ; INSERT INTO oly.amaze_log_report SELECT $1, 'DATA', 'MISSING_NEWREF_DECLARATION', 'ERROR', tmp.error_count, 'Missing NEW reference declaration for ' || tmp.class_name || '.' || tmp.feature_name FROM ( SELECT count (DISTINCT LDO.new_value) AS error_count, LDO.class AS class_name, LDO.feature AS feature_name FROM oly.amaze_log_database_object AS LDO LEFT JOIN oly.amaze_log_object AS LO ON ((LO.batch, LO.id) = (LDO.batch, LDO.new_value)) WHERE LDO.batch = $1 AND LO.batch IS NULL GROUP BY LDO.class, LDO.feature ) AS tmp WHERE tmp.error_count > 0 ; SELECT count(*) AS error_count FROM oly.amaze_log_report WHERE batch = $1; 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! I'm really wondering why the functions are so fast comparing to the classical SQL statement. Any ideas? -- Downloading signature ... 99% *CRC FAILED* signature aborted