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 918C432A17A for ; Tue, 28 Sep 2004 14:09:29 +0100 (BST) 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 22300-03 for ; Tue, 28 Sep 2004 13:09:16 +0000 (GMT) Received: from matrix.gatewaynet.com (matrix.gatewaynet.com [217.19.69.50]) by svr1.postgresql.org (Postfix) with ESMTP id 4593932A167 for ; Tue, 28 Sep 2004 14:09:18 +0100 (BST) Received: from matrix.gatewaynet.com (localhost.localdomain [127.0.0.1]) by matrix.gatewaynet.com (8.12.8/8.12.8) with ESMTP id i8SCOECC030291; Tue, 28 Sep 2004 15:24:14 +0300 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.8/8.12.8/Submit) with ESMTP id i8SCODMw030287; Tue, 28 Sep 2004 15:24:14 +0300 Date: Tue, 28 Sep 2004 15:24:13 +0300 (EEST) From: Achilleus Mantzios To: Martin Marques Cc: pgsql-sql@postgresql.org Subject: Re: Best way to know if there is a row In-Reply-To: <200409280955.23773.martin@bugs.unl.edu.ar> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-7 Content-Transfer-Encoding: 8BIT X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/241 X-Sequence-Number: 19087 O Martin Marques έγραψε στις Sep 28, 2004 : > I have a bunch of queries in a system I'm finishing, and I bumped with a > question on performace. > Which is the best way to solve this: > > I need to know if there is at least one row in the relation that comes from a > determinated query. Which is the best way to do this: > > (a) Build the query with "SELECT * ..." and after executing the query see if > numRows()>0 > (b) Build the query with "SELECT count(*) ...", fetch the row and see if > count>0 You could also try (c) SELECT exists (select 1 ... limit 1) and test the boolean value in the one and only row returned, where "..." is your clause as in (a),(b). > > I'm working with (a) because I see it better in performace, but I wanted to be > sure the numRows() will actually give me the exact amount of rows (had some > problems in the past with Informix). > > The aplication is written in PHP. > > -- -Achilleus