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 4897EDAC49 for ; Mon, 24 Oct 2005 01:35:08 -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 04182-05 for ; Mon, 24 Oct 2005 04:35:06 +0000 (GMT) Received: from davinci.ethosmedia.com (server227.ethosmedia.com [209.128.84.227]) by svr1.postgresql.org (Postfix) with ESMTP id 18D75DABED for ; Mon, 24 Oct 2005 01:35:05 -0300 (ADT) X-EthosMedia-Virus-Scanned: no infections found Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 8335801; Sun, 23 Oct 2005 21:37:34 -0700 From: Josh Berkus Organization: Aglio Database Solutions To: "Karl O. Pinc" Subject: Re: Using LIMIT 1 in plpgsql PERFORM statements Date: Sun, 23 Oct 2005 21:36:35 -0700 User-Agent: KMail/1.8 Cc: pgsql-performance@postgresql.org References: <1129957521l.27845l.2l@mofo> <200510231402.35612.josh@agliodbs.com> <1130114418l.8670l.2l@mofo> In-Reply-To: <1130114418l.8670l.2l@mofo> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200510232136.35790.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.01 required=5 tests=[AWL=0.010] X-Spam-Level: X-Archive-Number: 200510/328 X-Sequence-Number: 15096 Karl, > I like to write PERFORMs that return a constant when > selecting from a table. It emphasizes that the > selection is being done for its side effects. Well, there's always the destruction test: run each version of the function 10,000 times and see if there's an execution time difference. > (Programs should be written for people to read > and only incidentally for computers to execute. > Programs that people can't read quickly > become useless whereas programs that can't run > quickly can be fixed. Computers are easy. > People are difficult.) That's a nice sentiment, but I don't see how it applies. For example, if I do: SELECT id INTO v_check FROM some_table ORDER BY id LIMIT 1; IF id > 0 THEN .... ... that says pretty clearly to code maintainers that I'm only interested in finding out whether there's any rows in the table, while making sure I use the index on ID. If I want to make it more clear, I do: -- check whether the table is populated Not that there's anything wrong with your IF FOUND approach, but let's not mix up optimizations and making your code pretty ... especially for a SQL scripting language. -- Josh Berkus Aglio Database Solutions San Francisco