X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 7B6E19DC835 for ; Thu, 26 Jan 2006 13:13:38 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 55089-10 for ; Thu, 26 Jan 2006 13:13:36 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from bob.planeti.biz (unknown [66.98.130.45]) by postgresql.org (Postfix) with ESMTP id 1D46F9DC809 for ; Thu, 26 Jan 2006 13:13:34 -0400 (AST) Received: from fatchubby (cpe-071-070-134-248.nc.res.rr.com [71.70.134.248]) by bob.planeti.biz (8.12.10/8.12.5) with SMTP id k0QH3VAn016899 for ; Thu, 26 Jan 2006 12:03:32 -0500 From: J@Planeti.Biz Message-ID: <009a01c6229b$d67c6670$0d310d05@fatchubby> To: References: <786c2f6d0601260206k2201a548p48af7c7fc085d3b2@mail.gmail.com> <005d01c6228f$3772dca0$0d310d05@fatchubby> <43D8F4FD.4040703@modgraph-usa.com> <008001c62295$156b8fc0$0d310d05@fatchubby> <43D8FD39.8000408@archonet.com> Subject: Re: Query optimization with X Y JOIN Date: Thu, 26 Jan 2006 12:13:33 -0500 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=response Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2527 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.62 required=5 tests=[AWL=-0.099, BIZ_TLD=1.169, NO_REAL_NAME=0.55] X-Spam-Score: 1.62 X-Spam-Level: * X-Archive-Number: 200601/446 X-Sequence-Number: 16924 Yes, that helps a great deal. Thank you so much. ----- Original Message ----- From: "Richard Huxton" To: Cc: Sent: Thursday, January 26, 2006 11:47 AM Subject: Re: [PERFORM] Query optimization with X Y JOIN > J@Planeti.Biz wrote: >> If I want my database to go faster, due to X then I would think that the >> issue is about performance. I wasn't aware of a paticular constraint on >> X. > > You haven't asked a performance question yet though. > >> I have more that a rudementary understanding of what's going on here, I >> was just hoping that someone could shed some light on the basic principal >> of this JOIN command and its syntax. Most people I ask, don't give me >> straight answers and what I have already read on the web is not very >> helpful thus far. > > OK - firstly it's not a JOIN command. It's a SELECT query that happens to > join (in your example) three tables together. The syntax is specified in > the SQL reference section of the manuals, and I don't think it's different > from the standard SQL spec here. > > A query that joins two or more tables (be they real base-tables, views or > sub-query result-sets) produces the product of both. Normally you don't > want this so you apply constraints to that join (table_a.col1 = > table_b.col2). > > In some cases you want all the rows from one side of a join, whether or > not you get a match on the other side of the join. This is called an outer > join and results in NULLs for all the columns on the "outside" of the > join. A left-join returns all rows from the table on the left of the join, > a right-join from the table on the right of it. > > When planning a join, the planner will try to estimate how many matches it > will see on each side, taking into account any extra constraints (you > might want only some of the rows in table_a anyway). It then decides > whether to use any indexes on the relevant column(s). > > Now, if you think the planner is making a mistake we'll need to see the > output of EXPLAIN ANALYSE for the query and will want to know that you've > vacuumed and analysed the tables in question. > > Does that help at all? > -- > Richard Huxton > Archonet Ltd > > ---------------------------(end of broadcast)--------------------------- > TIP 2: Don't 'kill -9' the postmaster >