Article View: borland.public.interbase.sql
Article #633Re: optimizing query ..
From: Wayne Niddery [TeamB]
Date: Fri, 14 Sep 2007 14:46
Date: Fri, 14 Sep 2007 14:46
63 lines
2919 bytes
2919 bytes
Karol Bieniaszewski wrote: > > FROM > TABLE_B B > INNER JOIN TABLE_A A ON B.ID_OBJ=A.ID > INNER JOIN TABLE_C C ON C.ID_OBJ=A.ID AND B.SYSTEM=C.SYSTEM AND > C.ZRODLO=:PARAM_X > WHERE > B.KOD=PARAM_Y > AND B.SYSTEM=PARAM_Z Don't know if it will change anything, but "C.ZRODLO=:PARAM_X" should be in the Where clause, not in the join condition. > FROM > TABLE_B B > INNER JOIN TABLE_A A ON B.ID_OBJ=A.ID > INNER JOIN (TABLE_C C LEFT JOIN TABLE_D D ON C.ALARM=D.NAZWA) ON > C.ID_OBJ=A.ID AND B.SYSTEM=C.SYSTEM AND C.ZRODLO=:PARAM_X > WHERE > B.KOD=PARAM_Y > AND B.SYSTEM=PARAM_Z I have never seen any advantage in nesting joins, breaking them out as you do below is more readable, and, IME, has no negative effect on performance. > FROM > TABLE_B B > INNER JOIN TABLE_A A ON B.ID_OBJ=A.ID > INNER JOIN TABLE_C C ON C.ID_OBJ=A.ID AND B.SYSTEM=C.SYSTEM AND > C.ZRODLO=:PARAM_X > LEFT JOIN TABLE_D D ON C.ALARM=D.NAZWA > WHERE > B.KOD=PARAM_Y > AND B.SYSTEM=PARAM_Z > > but without success > now A is NATURAL A natural scan on A is more easily understandable here because you clearly have no conditions on table A, thus it makes more sense to simply scan it and perform indexed lookups in the other tables. What performance are you getting with this version compared to any of the others? I would try this: FROM TABLE_C C INNER JOIN TABLE_A A ON A.ID=C.ID_OBJ INNER JOIN TABLE_B B ON B.ID_OBJ=C.ID_OBJ AND B.SYSTEM=C.SYSTEM LEFT JOIN TABLE_D D ON D.NAZWA=C.ALARM WHERE C.ZRODLO=:PARAM_X AND B.KOD=:PARAM_Y AND B.SYSTEM=:PARAM_Z How does that change the plan and performance? -- Wayne Niddery - Winwright, Inc (www.winwright.ca) "I would remind you that extremism in the defense of liberty is no vice! And let me remind you also that moderation in the pursuit of justice is no virtue!" - Barry Goldwater
Technical Details
Message-ID:
<46ea9edd$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<46ea51f5$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,27cb88e47143e0c2 X-Google-Attributes: gid114a0e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Wayne Niddery [TeamB]" <wniddery@chaffaci.on.ca> From: "Wayne Niddery [TeamB]" <wniddery@chaffaci.on.ca> Newsgroups: borland.public.interbase.sql References: <46ea51f5$1@newsgroups.borland.com> Subject: Re: optimizing query .. Date: Fri, 14 Sep 2007 10:46:52 -0400 Lines: 65 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 69.17.170.228 Message-ID: <46ea9edd$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1189781213 69.17.170.228 (14 Sep 2007 07:46:53 -0700) X-Authenticated-User: wniddery Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail