Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 0083A9FB662 for ; Mon, 9 Oct 2006 11:19:18 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 35194-10 for ; Mon, 9 Oct 2006 11:19:16 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.174]) by postgresql.org (Postfix) with ESMTP id C35099FB661 for ; Mon, 9 Oct 2006 11:19:15 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id 30so579906ugc for ; Mon, 09 Oct 2006 07:19:14 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ISyQRUQuRCwJQmh0HX0WEDDwzKbGeJWtDdZx0wh0oTT+C4txcoej4MAPgxgYTEr/iwA6X1WMWNBUSQ4gg++kGk5c/WO4fPjKwTGpdWFM1bnAWWYZDtG2sVRQZy2Uu1YuaNjVpKKe5Kbs5JsIQQnoX+3lWt95p7ARUwiB1B0siWY= Received: by 10.78.182.20 with SMTP id e20mr5328961huf; Mon, 09 Oct 2006 07:19:13 -0700 (PDT) Received: by 10.78.35.18 with HTTP; Mon, 9 Oct 2006 07:19:13 -0700 (PDT) Message-ID: Date: Mon, 9 Oct 2006 10:19:13 -0400 From: "Merlin Moncure" To: "Jim C. Nasby" Subject: Re: Performance Optimization for Dummies 2 - the SQL Cc: "Carlo Stonebanks" , pgsql-performance@postgresql.org In-Reply-To: <20061008203450.GK72517@nasby.net> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20061008203450.GK72517@nasby.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.204 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, SPF_PASS X-Spam-Level: X-Archive-Number: 200610/158 X-Sequence-Number: 21287 On 10/8/06, Jim C. Nasby wrote: > On Thu, Oct 05, 2006 at 09:30:45AM -0400, Merlin Moncure wrote: > > I personally only use explicit joins when doing outer joins and even > > them push them out as far as possible. > > I used to be like that too, until I actually started using join syntax. > I now find it's *way* easier to identify what the join conditions are, > and to seperate them from the rest of the where clause. It also makes it > pretty much impossible to mess up a join clause and get a cartesian > product. > > If you are going to put the join clauses in the WHERE clause, at least > put a space between the join stuff and the rest of the WHERE clause. I use the row constructor to define key relationships for non trivial queries i.e. select foo.*, bar.* from foo f, bar b where (f.a, f.b, f.c) = (b.a, b.b, b.c) -- etc I am a really big fan of the row constructor, especially since we can do proper key ordering in 8.2. by convention I do relating first, filtering second. for really complex queries I will inline comment each line of the where clause: where (p.a) = (pd.b) and -- match part to part description pd.type != 'A' -- not using archived parts as to unwanted cartesian products, I test all prodution queries in the shell first. The really complex ones are somewhat trial and error process after all these years :) being something of a mathematical guy, I love sql for its (mostly) functional nature but hate the grammar. reminds me a little bit too much of cobol. the join syntax is just too much for me, although with left/right/natural joins there is no other way, and I very much agree with Carlo wrt oracle's nonstandard join syntax being more elegant. merlin