X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0971E529C0 for ; Fri, 29 Jul 2005 10:33:43 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 39505-06 for ; Fri, 29 Jul 2005 13:33:32 +0000 (GMT) Received: from dorado.vub.ac.be (dorado.vub.ac.be [134.184.129.10]) by svr1.postgresql.org (Postfix) with ESMTP id 7B1BA529DA for ; Fri, 29 Jul 2005 10:33:31 -0300 (ADT) Received: from mach.vub.ac.be (maxi.vub.ac.be [134.184.129.8]) by dorado.vub.ac.be (Postfix) with ESMTP id 8F693C4 for ; Fri, 29 Jul 2005 15:33:30 +0200 (CEST) Received: by mach.vub.ac.be (Postfix, from userid 21099) id 6AD978D0D; Fri, 29 Jul 2005 15:33:29 +0200 (CEST) Received: from olivier.amaze.ulb.ac.be (ucmbsgi10.ulb.ac.be [164.15.109.34]) by mach.vub.ac.be (Postfix) with ESMTP id E9C288D09 for ; Fri, 29 Jul 2005 15:33:27 +0200 (CEST) Date: Fri, 29 Jul 2005 15:33:26 +0200 To: pgsql-sql@postgresql.org Subject: Why are these queries so different in time? 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/8.01 (MacPPC, build 2092) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200507/240 X-Sequence-Number: 22218 Hi, I have a question about performance querying a 7.4 database. The orginal generated query was SELECT DISTINCT _compound0.object_id AS "ObjectId" FROM amaze._compound _compound0 LEFT JOIN amaze._product _product7 ON (_compound0.object_id = _product7.compound) LEFT JOIN amaze._database_object _database_object11 ON (_product7.reaction = _database_object11.object_id) LEFT JOIN amaze._educt _educt2 ON (_compound0.object_id = _educt2.compound) LEFT JOIN amaze._database_object _database_object6 ON (_educt2.reaction = _database_object6.object_id) WHERE ( _database_object6.label = '2-Isopropylmalate + CoA <= Acetyl-CoA + 3-Methyl-2-oxobutanoate + H2O' OR _database_object11.label = '2-Isopropylmalate + CoA <= Acetyl-CoA + 3-Methyl-2-oxobutanoate + H2O' ); This on take a huge time to perform, which may come to a timeout on the front-end application that uses the database. So, I decided to modify manually the query like this: SELECT DISTINCT _compound0.object_id AS "ObjectId" FROM amaze._compound _compound0 LEFT JOIN amaze._product _product7 ON (_compound0.object_id = _product7.compound) LEFT JOIN amaze._database_object _database_object11 ON (_product7.reaction = _database_object11.object_id) WHERE ( _database_object11.label = '2-Isopropylmalate + CoA <= Acetyl-CoA + 3-Methyl-2-oxobutanoate + H2O' ) UNION SELECT DISTINCT _compound0.object_id AS "ObjectId" FROM amaze._compound _compound0 LEFT JOIN amaze._educt _educt2 ON (_compound0.object_id = _educt2.compound) LEFT JOIN amaze._database_object _database_object6 ON (_educt2.reaction = _database_object6.object_id) WHERE ( _database_object6.label = '2-Isopropylmalate + CoA <= Acetyl-CoA + 3-Methyl-2-oxobutanoate + H2O' ) This should give the same result set, but it's really faster than the previous one, more than one thousand time faster. Is there a reason for this huge difference of performance? Thanks in advance. -- Olivier Hubaut North Bears Team SCMBB - ULB