Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Select max fro a table!

Re: Select max fro a table!

From: Jonathan Lewis <jonathan_at_jlcomp.demon.co.uk>
Date: Fri, 22 Jan 1999 20:10:54 -0000
Message-ID: <917035804.29613.0.nnrp-02.9e984b29@news.demon.co.uk>


It is a quirky feature that Oracle will not make the 'obvious' choice of path in this case, but uses your PK to select all the dates (because that is quicker than a tablescan) and then does a 'sort group by'.

Try

    select /*+ index_desc(table_a index_pk_name) */

        val_dte
    from

        table_a
    where rownum = 1
    ;

I don't like this hint, as it depends on the existence of the index completely, and would silently go wrong if someone dropped and rebuilt the index with a different name - but you may feel happy with it.

Jonathan Lewis
Yet another Oracle-related web site: www.jlcomp.demon.co.uk

Yeung Man wrote in message <788km3$5hc1_at_news.hk.linkage.net>...
>Hi,
> We have a table as Table_A ( val_dte not null, count number(4)) where
>val_dte is primary key. If we issue the sql
> select max(val_dte) from TAble_A;
> The sql has a long time to run. We use the explain plan as find the sql
>use the pk. Do anyone have idea what going on.
> TIA.
>
>Best Regards,
>Man
>
>
>
Received on Fri Jan 22 1999 - 14:10:54 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US