Re: Nested queries V/S Joins
Posted in 1996
> What is more efficient nested subqueries or joins?
Depends.
>Query 1:
>
> select item from a, b
> where a.item = b.item and> b.num = 50;
>
>Query 2:
>
> select item from a
> where item in (select item from b where b.num = 50);>
>If I "set explain on" on the above two queries, Query 1 has a higher
>estimated cost than Query 2, but the execution times (reported by time)
>are less for Query 1.
What you will find if you put a lot of data into tables a and b is that Q2
will run faster and generally return more consistent response times. Q1 will
degrade consistently over time. Depending on indexes, YMMV, etc.
>What does the "estimated cost of a query" mean anyway?
It's a pretty arbitrary indication of how long the query should take. In
general, the bigger the number, the longer a query will take (allegedly),
but there doesn't seem to be any way of translating the number into time.
HTH.
--
Cheers,
Billy
"Have you got it yet?" (c) Dazza, 1995