pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Merlin Moncure <mmoncure@gmail.com>
To: Jim C. Nasby <jim@nasby.net>
Cc: Carlo Stonebanks <stonec.register@sympatico.ca>
Cc: pgsql-performance@postgresql.org
Subject: Re: Performance Optimization for Dummies 2 - the SQL
Date: Mon, 9 Oct 2006 10:19:13 -0400
Message-ID: <b42b73150610090719x62493390r46c9dbd5e9e673c6@mail.gmail.com> (raw)
In-Reply-To: <20061008203450.GK72517@nasby.net>
References: <eft782$5a1$1@news.hub.org>
	<efu8tf$1blk$1@news.hub.org>
	<b42b73150610031221y4955e663ped999a83a810d318@mail.gmail.com>
	<eg0u6e$hbr$1@news.hub.org>
	<b42b73150610041407y3554f311u1329c4f3bdc53999@mail.gmail.com>
	<eg1dai$1tfa$1@news.hub.org>
	<b42b73150610042326v7fdeed17rf6b96e52a681a6db@mail.gmail.com>
	<eg2cds$29en$1@news.hub.org>
	<b42b73150610050630t76e9eedeh45a382729d35f2f6@mail.gmail.com>
	<20061008203450.GK72517@nasby.net>

On 10/8/06, Jim C. Nasby <jim@nasby.net> 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



view thread (38+ messages)  latest in thread

Message-ID: <b42b73150610090719x62493390r46c9dbd5e9e673c6@mail.gmail.com>
Permalink:  ../b42b73150610090719x62493390r46c9dbd5e9e673c6@mail.gmail.com/
Also on:    postgresql.org/message-id/b42b73150610090719x62493390r46c9dbd5e9e673c6@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: mmoncure@gmail.com, jim@nasby.net, stonec.register@sympatico.ca
  Subject: Re: Performance Optimization for Dummies 2 - the SQL
  In-Reply-To: <b42b73150610090719x62493390r46c9dbd5e9e673c6@mail.gmail.com>
  References: <eft782$5a1$1@news.hub.org> <efu8tf$1blk$1@news.hub.org> <b42b73150610031221y4955e663ped999a83a810d318@mail.gmail.com> <eg0u6e$hbr$1@news.hub.org> <b42b73150610041407y3554f311u1329c4f3bdc53999@mail.gmail.com> <eg1dai$1tfa$1@news.hub.org> <b42b73150610042326v7fdeed17rf6b96e52a681a6db@mail.gmail.com> <eg2cds$29en$1@news.hub.org> <b42b73150610050630t76e9eedeh45a382729d35f2f6@mail.gmail.com> <20061008203450.GK72517@nasby.net> <b42b73150610090719x62493390r46c9dbd5e9e673c6@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox