X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 47BDCDAA43 for ; Sat, 22 Oct 2005 01:55:11 -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 49248-07 for ; Sat, 22 Oct 2005 04:55:09 +0000 (GMT) Received: from mail22.sea5.speakeasy.net (mail22.sea5.speakeasy.net [69.17.117.24]) by svr1.postgresql.org (Postfix) with ESMTP id 77E67DAA34 for ; Sat, 22 Oct 2005 01:55:09 -0300 (ADT) Received: (qmail 28381 invoked from network); 22 Oct 2005 04:55:09 -0000 Received: from dsl017-073-250.chi4.dsl.speakeasy.net (HELO mofo.meme.com) ([69.17.73.250]) (envelope-sender ) by mail22.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 22 Oct 2005 04:55:09 -0000 Received: from mofo (localhost.localdomain [127.0.0.1]) by mofo.meme.com (Postfix) with ESMTP id 258E66E422 for ; Sat, 22 Oct 2005 00:05:21 -0500 (CDT) Date: Sat, 22 Oct 2005 05:05:21 +0000 From: "Karl O. Pinc" Subject: Using LIMIT 1 in plpgsql PERFORM statements To: pgsql-performance@postgresql.org X-Mailer: Balsa 2.3.0 Message-Id: <1129957521l.27845l.2l@mofo> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; DelSp=Yes; Format=Flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.05 required=5 tests=[FORGED_RCVD_HELO=0.05] X-Spam-Level: X-Archive-Number: 200510/303 X-Sequence-Number: 15071 Hi, I'm wondering if the plpgsql code: PERFORM 1 FROM foo; IF FOUND THEN ... is any slower than: PERFORM 1 FROM foo LIMIT 1; IF FOUND THEN ... Seems like it _could_ be smart enough to know that 1) It's selecting from a real table and not a function 2) GET DIAGNOSTICS is not used and therefore it does not have to do more than set FOUND, and need find only one row/plan the query to find only one row. I'm particularly interested in the query plan optimization aspect. Would it be considered poor practice to rely on such an optimization? Thanks. Karl Free Software: "You don't pay back, you pay forward." -- Robert A. Heinlein