Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have to say that I do not see the same behaviour in 11.2</p> <p>If I set up a test case as follows and updated from 10k to 1m rows in response to Vincent's comment</p> <pre><code>set linesize 130 set pagesize 0 create table mytable ( sdate date ); Table created. insert into mytable select sysdate - level from dual connect by level &lt;= 1000000; commit; 1000000 rows created. Commit complete. alter table mytable add constraint pk_mytable primary key ( sdate ) using index; Table altered. begin dbms_stats.gather_table_stats( user, 'MYTABLE' , estimate_percent =&gt; 100 , cascade =&gt; true ); end; / PL/SQL procedure successfully completed. </code></pre> <p>Then, executing your queries I get <em>almost</em> identical looking explain plans (notice the different types of INDEX FULL SCAN) </p> <pre><code>explain plan for select min(sdate) from mytable; Explained. select * from table(dbms_xplan.display); Plan hash value: 3877058912 ----------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 8 | 1 (0)| 00:00:01 | | 1 | SORT AGGREGATE | | 1 | 8 | | | | 2 | INDEX FULL SCAN (MIN/MAX)| PK_MYTABLE | 1 | 8 | 1 (0)| 00:00:01 | ----------------------------------------------------------------------------------------- 9 rows selected. explain plan for select min(sdate), max(sdate) from mytable; Explained. select * from table(dbms_xplan.display); Plan hash value: 3812733167 ------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 8 | 252 (0)| 00:00:04 | | 1 | SORT AGGREGATE | | 1 | 8 | | | | 2 | INDEX FULL SCAN| PK_MYTABLE | 1000K| 7812K| 252 (0)| 00:00:04 | ------------------------------------------------------------------------------- 9 rows selected. </code></pre> <p>To quote from a previous answer of mine:</p> <blockquote> <p>The two most common reasons for a query not using indexes are:</p> <ol> <li>It's quicker to do a full table scan.</li> <li>Poor statistics.</li> </ol> </blockquote> <p>Unless there's something you're not posting in the question my immediate answer would be that you have not collected statistics on this table, you haven't collected them with a high enough estimate percent or you've used <a href="http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_4005.htm#SQLRF01105" rel="nofollow"><code>analyze</code></a>, which will <em>not</em> help the Cost Based Optimizer, unlike <a href="http://docs.oracle.com/cd/E11882_01/server.112/e25494/general002.htm#ADMIN11525" rel="nofollow"><code>dbms_stats.gather_table_stats</code></a>.</p> <p>To quote from the documentation on <code>analyze</code>:</p> <blockquote> <p>For the collection of most statistics, use the DBMS_STATS package, which lets you collect statistics in parallel, collect global statistics for partitioned objects, and fine tune your statistics collection in other ways. See Oracle Database PL/SQL Packages and Types Reference for more information on the DBMS_STATS package. </p> <p>Use the ANALYZE statement (rather than DBMS_STATS) for statistics collection not related to the cost-based optimizer:</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload