Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Why DISTINCT is costly?
"Dan Koren" <dankoren_at_yahoo.com> wrote:
> <juhunu_at_gmail.com> wrote in message
> news:1126507505.386016.211310_at_f14g2000cwb.googlegroups.com...
> > Whenever I use a DISTINCT in my query, I see the "SORT UNIQUE" getting
> > added to the execution plan.
> >
> > "SORT UNIQUE" is increasing the cost of the query by a greater factor.
> >
> > Any help in reducing the cost in using DISTINCT would be of much help.
I think that changing the second occurence of "foo" in your query into "bar" should do it.
> >
>
> And how else would one be able to
> eliminate duplicates without sort
> unique?
How about by using a hash? Oracle had become so hash-happy in version 9 (for joins), I don't know why they don't consider using hashes for "distinct" (and "group by") also. Or maybe 10g does consider them.
Anyway, I sometimes drop the distinct from the SQL and implement it on the "client" side using a hash (in Perl).
Xho
-- -------------------- http://NewsReader.Com/ -------------------- Usenet Newsgroup Service $9.95/Month 30GBReceived on Mon Sep 12 2005 - 14:01:55 CDT