X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 193149FA5DD for ; Tue, 4 Jul 2006 13:25:36 -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 04227-01 for ; Tue, 4 Jul 2006 13:25:26 -0300 (ADT) X-Greylist: delayed 00:06:40.346015 by SQLgrey- Received: from mail.89glass.com (mail.89glass.com [72.10.2.250]) by postgresql.org (Postfix) with SMTP id 920B49FA4A5 for ; Tue, 4 Jul 2006 13:25:25 -0300 (ADT) Received: (qmail 13652 invoked by uid 1006); 4 Jul 2006 16:18:44 -0000 Received: from 192.168.254.111 by lumberjack (envelope-from , uid 201) with qmail-scanner-1.25 (clamdscan: 0.67. Clear:RC:1(192.168.254.111):. Processed in 0.035349 secs); 04 Jul 2006 16:18:44 -0000 Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=domkey; d=rbsinteractive.com; b=PdaWc4/8r3pxP/NaEYpuOA+pM64F/skZqTvFuhUVF5kOoGcpmQ5vrJY6I0w3x6Ch6qv8FKARrXjQkkM3S+ZYGlgumtZLZ2LZWmGpWeB6ts0WtUDZBLd8r9LA8CH80gBp9I66cboK09cZN3CpWNrqJN47wRwh8wNAVjLFDV+sDio= ; Received: from unknown (HELO ?192.168.254.111?) (192.168.254.111) by mail.89glass.com with SMTP; 4 Jul 2006 16:18:44 -0000 Message-ID: <44AA94E3.9040301@rbsinteractive.com> Date: Tue, 04 Jul 2006 09:18:43 -0700 From: Nolan Cafferky User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Luckys CC: pgsql-performance@postgresql.org Subject: Re: how to tune this query. References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/19 X-Sequence-Number: 19879 I don't think indexes are going to help you here - with the FULL OUTER JOINs, the query will have to look at and include each row from each table you query from anyway, so it's going to choose sequential scans. In addition, some of the lower join conditions are going to take forever. What's is your goal? The volume of data that I imagine this query would produce can't possibly be useful. I'm guessing at the very least you'll want to LEFT OUTER JOIN everything back against STG_Property, and leave the other join conditions out of each ON statement. Luckys wrote: > Hi all, > I got this query, I'm having indexes for PropertyId and Dates columns > across all the tables, but still it takes ages to get me the result. > What indexes would be proposed on this, or I'm helpless? > > FROM STG_Property a > > FULL OUTER JOIN > STG_PropConfirmedLogs b > ON (a.PropertyId = b.PropertyId AND a.p_LastModified = > b.p_Modified_Date) > > FULL OUTER JOIN > STG_PropConnectionFeesLogs c > ON ((a.PropertyId = c.PropertyId AND a.p_LastModified = c.p_ChangedOn) > OR (b.PropertyId = c.PropertyId AND b.p_Modified_Date = > c.p_ChangedOn)) > > FULL OUTER JOIN > STG_PropDeletedLogs d > ON ((a.PropertyId = d.PropertyId AND a.p_LastModified = d.p_DeletedOn) > OR (b.PropertyId = d.PropertyId AND b.p_Modified_Date = > d.p_DeletedOn) > OR ( c.PropertyId = d.PropertyId AND c.p_ChangedOn = d.p_DeletedOn)) > > FULL OUTER JOIN > STG_PropFEWALogs e > ON ((a.PropertyId = e.PropertyId AND a.p_LastModified = > e.p_Modified_Date) > OR (b.PropertyId = e.PropertyId AND b.p_Modified_Date = > e.p_Modified_Date) OR (c.PropertyId = e.PropertyId AND c.p_ChangedOn > = e.p_Modified_Date) > OR (d.PropertyId = e.PropertyId AND d.p_DeletedOn = > e.p_Modified_Date)) > > FULL OUTER JOIN > STG_PropInSewerNetworkLogs f > ON ((a.PropertyId = f.PropertyId AND a.p_LastModified = > f.p_Modified_Date) > OR (b.PropertyId = f.PropertyId AND b.p_Modified_Date = > f.p_Modified_Date) > OR (c.PropertyId = f.PropertyId AND c.p_ChangedOn = > f.p_Modified_Date) > OR (d.PropertyId = f.PropertyId AND d.p_DeletedOn = > f.p_Modified_Date) > OR (e.PropertyId = f.PropertyId AND e.p_Modified_Date = > f.p_Modified_Date)) FULL OUTER JOIN > STG_PropTypeLogs g > ON ((a.PropertyId = g .PropertyId AND a.p_LastModified = > g.p_LastModified) > OR (b.PropertyId = g.PropertyId AND b.p_Modified_Date = > g.p_LastModified) > OR (c.PropertyId = g.PropertyId AND c.p_ChangedOn = g.p_LastModified) > OR (d.PropertyId = g.PropertyId AND d.p_DeletedOn = g.p_LastModified) > OR (e.PropertyId = g.PropertyId AND e.p_Modified_Date = > g.p_LastModified) > OR (f.PropertyId = g.PropertyId AND f.p_Modified_Date = > g.p_LastModified)) > > -- Luckys -- Nolan Cafferky Software Developer IT Department RBS Interactive nolan.cafferky@rbsinteractive.com