Article View: borland.public.interbase.sql
Article #167Re: HAVING or WHERE
From: willr
Date: Thu, 26 Jun 2008 18:17
Date: Thu, 26 Jun 2008 18:17
31 lines
2216 bytes
2216 bytes
Bill Todd [TeamB] wrote: > Hs wrote: > >> What is happening? Generaly what is the difference in resuls and in >> background between calling HAVING or WHERE for non aggregation fields? > > In case one the optimizer elected to read farmer in natural order and > use the primary index of buy to locate the record in buy that matched > the current record in farmer. This means that every record in buy was > located in the index then read from disk before the WHERE conditions > could be applied. > > In case two the optimizer elected to sort farmer, sort buy then merge > the two streams. Although you cannot tell from the plan the WHERE and > HAVING conditions were probably applied to buy as it was read in > natural order so only the matching records had to be sorted and merged. > This resulted in much less I/O than locating all of the buy records one > at a time through the index. > > Why did the optimizer elect to use the index in one case and do a sort > merge in the other? Only one (or possibly two) people know and they are > in InterBase R&D.:) > According to "The Practical SQL Handbook", 3rd ed. the HAVING word causes grouping to occur first and then eliminates rows -- possibly cutting down the set to where a sort/merge is faster -- Will R PMC Consulting
Technical Details
Message-ID:
<4863dc7c@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mailReferences:
<48611ee3$1@newsgroups.borland.com> <48612c58$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,8b9906a31c39f622 X-Google-Attributes: gid114a0e,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Date: Thu, 26 Jun 2008 12:17:19 -0600 From: willr <willr@pmccl.com> User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 Newsgroups: borland.public.interbase.sql Subject: Re: HAVING or WHERE References: <48611ee3$1@newsgroups.borland.com> <48612c58$1@newsgroups.borland.com> In-Reply-To: <48612c58$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 189.174.176.59 Message-ID: <4863dc7c@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1214504060 189.174.176.59 (26 Jun 2008 11:14:20 -0700) Lines: 31 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!feeder.erje.net!news.isoc.lu!newsgroups.borland.com!not-for-mail