Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Why does Oracle need this Index ?
A copy of this was sent to "Roger" <NOrgSPAM_at_mcs-hh.de>
(if that email address didn't require changing)
On Mon, 30 Aug 1999 17:25:09 +0200, you wrote:
>I have the following query:
>
>select sum(vkpreise.preis) as s, count(*) as c from vkprlist, artikel,
>vkpreise where vkprlist.vkplname like 'B%' and vkprlist.vkplid =
>vkpreise.vkplid
> and vkpreise.produktnr = artikel.produktnr group by artikel.produktnr
>
>
>What I don't understand is, why Oracle needs an index on vkplname. If
>vkplname isn't indexed Oracle performs a full table scan on vkpreise ? Why ?
>I tested this query with two other database server and both don't need this
>index.
>
>Regards
> Roger
>
>
>
It sounds like you are using rule based optimizer.
If there is no index on vkplname, then there are no 'good' access paths to either of vkprlist or artikel or vkpreise -- they are all equally good. It must full scan ONE of them and then join to the others.
Using RBO -- the order of the tables (in light of the fact that no index exists from which to make a different plan) in the FROM clause is used to drive the order of the tables. It'll use the table on the rightmost of the from clause -- vkpreise. As far as the optimizer is concerned that is as good as full scanning either of the other 2 tables (they would have to be full scanned as well).
List the tables in order of preference of scanning -- if you want vkprlist to be scanned -- then put it last in the from clause.
--
See http://govt.us.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'...
Current article is "Part I of V, Autonomous Transactions" updated June 21'st
Thomas Kyte tkyte_at_us.oracle.com Oracle Service Industries Reston, VA USA
Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Mon Aug 30 1999 - 12:09:16 CDT