views:

86

answers:

4

I have a view where if I select like this:

select * from view where date = '17-sep-10'

it returns in seconds.

If I use a dynamic date:

select * 
  from view 
 where date = to_date((select current_business_date 
                         from v_business_day), 
                      'mm/dd/yyyy')

it returns in 20 mins.

Why would hard coding improve performance so much? Also, the select in the to_date is not the issue (I think). It returns almost instanteously when running it.

Here is the desc for the view:

JAID_OWNER@algoja1p> desc v_positions_rm_base
Name                                      Null?    Type
----------------------------------------- -------- ----------------------------
 RUN_KEY                                   NOT NULL NUMBER(10)
 POSITION_KEY                              NOT NULL NUMBER(10)
 POSITIONS                                          VARCHAR2(50)
 INSTRUMENT_ID                                      VARCHAR2(151)
 BUSINESS_DATE                             NOT NULL DATE
 PROCESSING_DATE                                    DATE
 PROCESSING_STATUS_KEY                     NOT NULL NUMBER(10)

Here is the explain plan for when I hardcode the date. I changed the query to do a to_date on a hardcoded value so it's consistent..

explain plan for select * from v_positions_rm_base where business_date = to_date('09/17/2010', 'mm/dd/yyyy')
-----------------------------------------------------------------------------------------------------------------------------       
| Id  | Operation                                    | Name                         | Rows  | Bytes | Cost (%CPU)| Time     |       
-----------------------------------------------------------------------------------------------------------------------------       
|   0 | SELECT STATEMENT                             |                              |   518 |  1003K|  1679   (2)| 00:00:21 |       
|*  1 |  FILTER                                      |                              |       |       |            |          |       
|*  2 |   FILTER                                     |                              |       |       |            |          |       
|*  3 |    HASH JOIN RIGHT OUTER                     |                              | 10360 |    19M|  1651   (2)| 00:00:20 |       
|   4 |     INDEX FAST FULL SCAN                     | RM_SRC_ACCT_UDX              |   601 |  7212 |     2   (0)| 00:00:01 |       
|   5 |     VIEW                                     |                              | 10360 |    19M|  1648   (2)| 00:00:20 |       
|*  6 |      HASH JOIN RIGHT OUTER                   |                              | 10360 |    20M|  1648   (2)| 00:00:20 |       
|   7 |       VIEW                                   | V_RM_FUTURES_CODE_TRANS_FLAT |     1 |    96 |     9  (12)| 00:00:01 |       
|   8 |        HASH GROUP BY                         |                              |     1 |    51 |     9  (12)| 00:00:01 |       
|   9 |         TABLE ACCESS BY INDEX ROWID          | CODE_TRANSLATION             |     3 |   153 |     8   (0)| 00:00:01 |       
|* 10 |          INDEX RANGE SCAN                    | CODE_TRANSLATION_IDX3        |     3 |       |     7   (0)| 00:00:01 |       
|* 11 |       HASH JOIN RIGHT OUTER                  |                              | 10360 |    19M|  1638   (2)| 00:00:20 |       
|  12 |        VIEW                                  | V_RM_FUTURES_CODE_TRANS_FLAT |     1 |    96 |     9  (12)| 00:00:01 |       
|  13 |         HASH GROUP BY                        |                              |     1 |    51 |     9  (12)| 00:00:01 |       
|  14 |          TABLE ACCESS BY INDEX ROWID         | CODE_TRANSLATION             |     3 |   153 |     8   (0)| 00:00:01 |       
|* 15 |           INDEX RANGE SCAN                   | CODE_TRANSLATION_IDX3        |     3 |       |     7   (0)| 00:00:01 |       
|* 16 |        HASH JOIN RIGHT OUTER                 |                              | 10360 |    18M|  1629   (2)| 00:00:20 |       
|  17 |         VIEW                                 | V_RM_FUTURES_CODE_TRANS_FLAT |   404 | 42420 |    12   (9)| 00:00:01 |       
|  18 |          HASH GROUP BY                       |                              |   404 | 20604 |    12   (9)| 00:00:01 |       
|  19 |           TABLE ACCESS BY INDEX ROWID        | CODE_TRANSLATION             |   404 | 20604 |    11   (0)| 00:00:01 |       
|* 20 |            INDEX RANGE SCAN                  | CODE_TRANS_TYPE_IDX          |   404 |       |     3   (0)| 00:00:01 |       
|* 21 |         HASH JOIN RIGHT OUTER                |                              | 10360 |    17M|  1616   (2)| 00:00:20 |       
|  22 |          VIEW                                | V_RM_FUTURES_CODE_TRANS_FLAT |   404 | 42420 |    12   (9)| 00:00:01 |       
|  23 |           HASH GROUP BY                      |                              |   404 | 20604 |    12   (9)| 00:00:01 |       
|  24 |            TABLE ACCESS BY INDEX ROWID       | CODE_TRANSLATION             |   404 | 20604 |    11   (0)| 00:00:01 |       
|* 25 |             INDEX RANGE SCAN                 | CODE_TRANS_TYPE_IDX          |   404 |       |     3   (0)| 00:00:01 |       
|* 26 |          HASH JOIN RIGHT OUTER               |                              | 10360 |    16M|  1603   (2)| 00:00:20 |       
|  27 |           TABLE ACCESS FULL                  | SOURCE_SYSTEM                |    68 |   748 |     3   (0)| 00:00:01 |       
|* 28 |           HASH JOIN RIGHT OUTER              |                              | 10360 |    16M|  1599   (2)| 00:00:20 |       
|  29 |            TABLE ACCESS BY INDEX ROWID       | CODE_TRANSLATION             |     1 |    51 |     2   (0)| 00:00:01 |       
|* 30 |             INDEX RANGE SCAN                 | CODE_TRANS_TYPE_IDX          |     1 |       |     1   (0)| 00:00:01 |       
|  31 |            VIEW                              |                              | 10360 |    16M|  1597   (2)| 00:00:20 |       
|* 32 |             HASH JOIN RIGHT OUTER            |                              | 10360 |  7527K|  1597   (2)| 00:00:20 |       
|  33 |              TABLE ACCESS BY INDEX ROWID     | PARAMETER_CONTROL            |     1 |    38 |     2   (0)| 00:00:01 |       
|* 34 |               INDEX RANGE SCAN               | PARAMETER_CONTROL_IDX3       |     1 |       |     1   (0)| 00:00:01 |       
|* 35 |              HASH JOIN RIGHT OUTER           |                              | 10360 |  7142K|  1594   (2)| 00:00:20 |       
|  36 |               VIEW                           | V_ENTITY_FLAT                |  1742 |   282K|    35   (9)| 00:00:01 |       
|* 37 |                HASH JOIN RIGHT OUTER         |                              |  1742 |   229K|    35   (9)| 00:00:01 |       
|  38 |                 INDEX FAST FULL SCAN         | ENTITY_IDX_5                 |  1742 | 40066 |     6   (0)| 00:00:01 |       
|* 39 |                 HASH JOIN RIGHT OUTER        |                              |  1742 |   190K|    28   (8)| 00:00:01 |       
|  40 |                  INDEX FAST FULL SCAN        | ENTITY_IDX_5                 |  1742 | 47034 |     6   (0)| 00:00:01 |       
|* 41 |                  HASH JOIN RIGHT OUTER       |                              |  1742 |   144K|    21   (5)| 00:00:01 |       
|  42 |                   INDEX FAST FULL SCAN       | ENTITY_IDX_5                 |  1742 | 47034 |     6   (0)| 00:00:01 |       
|* 43 |                   HASH JOIN RIGHT OUTER      |                              |  1742 |    98K|    15   (7)| 00:00:01 |       
|  44 |                    INDEX FAST FULL SCAN      | ENTITY_IDX_5                 |  1742 | 47034 |     6   (0)| 00:00:01 |       
|  45 |                    TABLE ACCESS FULL         | ENTITY                       |  1742 | 54002 |     8   (0)| 00:00:01 |       
|* 46 |               HASH JOIN RIGHT OUTER          |                              |  2432 |  1282K|  1559   (1)| 00:00:19 |       
|  47 |                TABLE ACCESS FULL             | INSTRUMENT_ID_TYPE           |     8 |    88 |     3   (0)| 00:00:01 |       
|* 48 |                HASH JOIN RIGHT OUTER         |                              |  2432 |  1256K|  1555   (1)| 00:00:19 |       
|  49 |                 TABLE ACCESS BY INDEX ROWID  | PROCESSING_STATUS            |     1 |    76 |     1   (0)| 00:00:01 |       
|* 50 |                  INDEX UNIQUE SCAN           | PROCESSING_STATUS_PK         |     1 |       |     0   (0)| 00:00:01 |       
|* 51 |                 HASH JOIN RIGHT OUTER        |                              |  2432 |  1075K|  1554   (1)| 00:00:19 |       
|* 52 |                  TABLE ACCESS BY INDEX ROWID | CODE_TRANSLATION             |     1 |    65 |     2   (0)| 00:00:01 |       
|* 53 |                   INDEX RANGE SCAN           | CODE_TRANS_TYPE_IDX          |     1 |       |     1   (0)| 00:00:01 |       
|* 54 |                  HASH JOIN RIGHT OUTER       |                              |  2432 |   921K|  1551   (1)| 00:00:19 |       
|* 55 |                   TABLE ACCESS BY INDEX ROWID| CODE_TRANSLATION             |     1 |    65 |     2   (0)| 00:00:01 |       
|* 56 |                    INDEX RANGE SCAN          | CODE_TRANS_TYPE_IDX          |     1 |       |     1   (0)| 00:00:01 |       
|* 57 |                   TABLE ACCESS BY INDEX ROWID| POSITIONS                    |  2432 |   767K|  1549   (1)| 00:00:19 |       
|* 58 |                    INDEX RANGE SCAN          | POSITIONS_IDX_01             |  5676 |       |   737   (2)| 00:00:09 |       
|* 59 |   INDEX RANGE SCAN                           | PARAMETER_CONTROL_IDX3       |     1 |    27 |     2   (0)| 00:00:01 |       
----------------------------------------------------------------------------------------------------------------------------- 

and here is the explain plan for the other view:

explain plan for select * from v_positions_rm_base where business_date = to_date((select current_business_date from v_business_day), 'mm/dd/yyyy');
-------------------------------------------------------------------------------------------------------------------------------       
| Id  | Operation                                      | Name                         | Rows  | Bytes | Cost (%CPU)| Time     |       
-------------------------------------------------------------------------------------------------------------------------------       
|   0 | SELECT STATEMENT                               |                              |   171K|   324M|   366K  (3)| 01:13:16 |       
|*  1 |  FILTER                                        |                              |       |       |            |          |       
|*  2 |   FILTER                                       |                              |       |       |            |          |       
|*  3 |    HASH JOIN RIGHT OUTER                       |                              |  3436K|  6485M|   366K  (3)| 01:13:16 |       
|   4 |     INDEX FAST FULL SCAN                       | RM_SRC_ACCT_UDX              |   601 |  7212 |     2   (0)| 00:00:01 |       
|*  5 |     VIEW                                       |                              |  3436K|  6446M|   366K  (3)| 01:13:15 |       
|*  6 |      HASH JOIN RIGHT OUTER                     |                              |  3436K|  6806M|   366K  (3)| 01:13:15 |       
|   7 |       VIEW                                     | V_RM_FUTURES_CODE_TRANS_FLAT |     1 |    96 |     9  (12)| 00:00:01 |       
|   8 |        HASH GROUP BY                           |                              |     1 |    51 |     9  (12)| 00:00:01 |       
|   9 |         TABLE ACCESS BY INDEX ROWID            | CODE_TRANSLATION             |     3 |   153 |     8   (0)| 00:00:01 |       
|* 10 |          INDEX RANGE SCAN                      | CODE_TRANSLATION_IDX3        |     3 |       |     7   (0)| 00:00:01 |       
|* 11 |       HASH JOIN RIGHT OUTER                    |                              |  3436K|  6492M|   366K  (3)| 01:13:15 |       
|  12 |        VIEW                                    | V_RM_FUTURES_CODE_TRANS_FLAT |     1 |    96 |     9  (12)| 00:00:01 |       
|  13 |         HASH GROUP BY                          |                              |     1 |    51 |     9  (12)| 00:00:01 |       
|  14 |          TABLE ACCESS BY INDEX ROWID           | CODE_TRANSLATION             |     3 |   153 |     8   (0)| 00:00:01 |       
|* 15 |           INDEX RANGE SCAN                     | CODE_TRANSLATION_IDX3        |     3 |       |     7   (0)| 00:00:01 |       
|* 16 |        HASH JOIN RIGHT OUTER                   |                              |  3436K|  6177M|   366K  (3)| 01:13:14 |       
|  17 |         VIEW                                   | V_RM_FUTURES_CODE_TRANS_FLAT |   404 | 42420 |    12   (9)| 00:00:01 |       
|  18 |          HASH GROUP BY                         |                              |   404 | 20604 |    12   (9)| 00:00:01 |       
|  19 |           TABLE ACCESS BY INDEX ROWID          | CODE_TRANSLATION             |   404 | 20604 |    11   (0)| 00:00:01 |       
|* 20 |            INDEX RANGE SCAN                    | CODE_TRANS_TYPE_IDX          |   404 |       |     3   (0)| 00:00:01 |       
|* 21 |         HASH JOIN RIGHT OUTER                  |                              |  3436K|  5833M|   366K  (3)| 01:13:13 |       
|  22 |          VIEW                                  | V_RM_FUTURES_CODE_TRANS_FLAT |   404 | 42420 |    12   (9)| 00:00:01 |       
|  23 |           HASH GROUP BY                        |                              |   404 | 20604 |    12   (9)| 00:00:01 |       
|  24 |            TABLE ACCESS BY INDEX ROWID         | CODE_TRANSLATION             |   404 | 20604 |    11   (0)| 00:00:01 |       
|* 25 |             INDEX RANGE SCAN                   | CODE_TRANS_TYPE_IDX          |   404 |       |     3   (0)| 00:00:01 |       
|* 26 |          HASH JOIN RIGHT OUTER                 |                              |  3436K|  5489M|   366K  (3)| 01:13:13 |       
|  27 |           TABLE ACCESS FULL                    | SOURCE_SYSTEM                |    68 |   748 |     3   (0)| 00:00:01 |       
|* 28 |           HASH JOIN RIGHT OUTER                |                              |  3436K|  5453M|   365K  (3)| 01:13:12 |       
|  29 |            TABLE ACCESS BY INDEX ROWID         | CODE_TRANSLATION             |     1 |    51 |     2   (0)| 00:00:01 |       
|* 30 |             INDEX RANGE SCAN                   | CODE_TRANS_TYPE_IDX          |     1 |       |     1   (0)| 00:00:01 |       
|  31 |            VIEW                                |                              |  3436K|  5286M|   365K  (3)| 01:13:11 |       
|* 32 |             HASH JOIN RIGHT OUTER              |                              |  3436K|  2438M|   365K  (3)| 01:13:11 |       
|  33 |              TABLE ACCESS BY INDEX ROWID       | PARAMETER_CONTROL            |     1 |    38 |     2   (0)| 00:00:01 |       
|* 34 |               INDEX RANGE SCAN                 | PARAMETER_CONTROL_IDX3       |     1 |       |     1   (0)| 00:00:01 |       
|  35 |              MERGE JOIN OUTER                  |                              |  3436K|  2313M|   365K  (3)| 01:13:11 |       
|  36 |               MERGE JOIN OUTER                 |                              |  3436K|  2064M|   365K  (3)| 01:13:11 |       
|  37 |                SORT JOIN                       |                              |   806K|   357M|   365K  (3)| 01:13:10 |       
|  38 |                 MERGE JOIN OUTER               |                              |   806K|   357M|   365K  (3)| 01:13:10 |       
|  39 |                  SORT JOIN                     |                              |   806K|   348M|   365K  (3)| 01:13:10 |       
|* 40 |                   HASH JOIN RIGHT OUTER        |                              |   806K|   348M|   365K  (3)| 01:13:10 |       
|* 41 |                    TABLE ACCESS BY INDEX ROWID | CODE_TRANSLATION             |     1 |    65 |     2   (0)| 00:00:01 |       
|* 42 |                     INDEX RANGE SCAN           | CODE_TRANS_TYPE_IDX          |     1 |       |     1   (0)| 00:00:01 |       
|* 43 |                    HASH JOIN RIGHT OUTER       |                              |   806K|   298M|   365K  (3)| 01:13:10 |       
|* 44 |                     TABLE ACCESS BY INDEX ROWID| CODE_TRANSLATION             |     1 |    65 |     2   (0)| 00:00:01 |       
|* 45 |                      INDEX RANGE SCAN          | CODE_TRANS_TYPE_IDX          |     1 |       |     1   (0)| 00:00:01 |       
|* 46 |                     TABLE ACCESS FULL          | POSITIONS                    |   806K|   248M|   365K  (3)| 01:13:09 |       
|* 47 |                  SORT JOIN                     |                              |     8 |    88 |     4  (25)| 00:00:01 |       
|  48 |                   TABLE ACCESS FULL            | INSTRUMENT_ID_TYPE           |     8 |    88 |     3   (0)| 00:00:01 |       
|* 49 |                SORT JOIN                       |                              |  1742 |   282K|    36  (12)| 00:00:01 |       
|  50 |                 VIEW                           | V_ENTITY_FLAT                |  1742 |   282K|    35   (9)| 00:00:01 |       
|* 51 |                  HASH JOIN RIGHT OUTER         |                              |  1742 |   229K|    35   (9)| 00:00:01 |       
|  52 |                   INDEX FAST FULL SCAN         | ENTITY_IDX_5                 |  1742 | 40066 |     6   (0)| 00:00:01 |       
|* 53 |                   HASH JOIN RIGHT OUTER        |                              |  1742 |   190K|    28   (8)| 00:00:01 |       
|  54 |                    INDEX FAST FULL SCAN        | ENTITY_IDX_5                 |  1742 | 47034 |     6   (0)| 00:00:01 |       
|* 55 |                    HASH JOIN RIGHT OUTER       |                              |  1742 |   144K|    21   (5)| 00:00:01 |       
|  56 |                     INDEX FAST FULL SCAN       | ENTITY_IDX_5                 |  1742 | 47034 |     6   (0)| 00:00:01 |       
|* 57 |                     HASH JOIN RIGHT OUTER      |                              |  1742 |    98K|    15   (7)| 00:00:01 |       
|  58 |                      INDEX FAST FULL SCAN      | ENTITY_IDX_5                 |  1742 | 47034 |     6   (0)| 00:00:01 |       
|  59 |                      TABLE ACCESS FULL         | ENTITY                       |  1742 | 54002 |     8   (0)| 00:00:01 |       
|* 60 |               SORT JOIN                        |                              |     1 |    76 |     2  (50)| 00:00:01 |       
|  61 |                TABLE ACCESS BY INDEX ROWID     | PROCESSING_STATUS            |     1 |    76 |     1   (0)| 00:00:01 |       
|* 62 |                 INDEX UNIQUE SCAN              | PROCESSING_STATUS_PK         |     1 |       |     0   (0)| 00:00:01 |       
|  63 |      MERGE JOIN CARTESIAN                      |                              |     1 |   119 |     4   (0)| 00:00:01 |       
|  64 |       MERGE JOIN CARTESIAN                     |                              |     1 |    81 |     3   (0)| 00:00:01 |       
|  65 |        MERGE JOIN CARTESIAN                    |                              |     1 |    54 |     2   (0)| 00:00:01 |       
|* 66 |         INDEX RANGE SCAN                       | PARAMETER_CONTROL_IDX3       |     1 |    27 |     1   (0)| 00:00:01 |       
|  67 |         BUFFER SORT                            |                              |     1 |    27 |     1   (0)| 00:00:01 |       
|* 68 |          INDEX RANGE SCAN                      | PARAMETER_CONTROL_IDX3       |     1 |    27 |     1   (0)| 00:00:01 |       
|  69 |        BUFFER SORT                             |                              |     1 |    27 |     2   (0)| 00:00:01 |       
|* 70 |         INDEX RANGE SCAN                       | PARAMETER_CONTROL_IDX3       |     1 |    27 |     1   (0)| 00:00:01 |       
|  71 |       BUFFER SORT                              |                              |     1 |    38 |     3   (0)| 00:00:01 |       
|* 72 |        TABLE ACCESS BY INDEX ROWID             | PARAMETER_CONTROL            |     1 |    38 |     1   (0)| 00:00:01 |       
|* 73 |         INDEX RANGE SCAN                       | PARAMETER_CONTROL_IDX1       |     2 |       |     0   (0)| 00:00:01 |       
|* 74 |   INDEX RANGE SCAN                             | PARAMETER_CONTROL_IDX3       |     1 |    27 |     2   (0)| 00:00:01 |       
-------------------------------------------------------------------------------------------------------------------------------       
A: 

Response to Cagcowboy

There is no issue with the to_date on the other side of the = from the column.

Only casting a COLUMN away from type is an issue.


Example:

create table index_test
as
select object_name, created as create_dt from all_objects;

create index it_create_dt_idx on index_test (create_dt) compute statistics;

INDEX is used with no issue with TO_DATE is NOT on the Column


set autotrace on explain
select * from index_test where create_dt = to_date('17-SEP-2000', 'DD-MON-YYYY');

Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=1 Card=1 Bytes=26)
   1    0   TABLE ACCESS (BY INDEX ROWID) OF 'INDEX_TEST' (TABLE) (Cos
          t=1 Card=1 Bytes=26)

   2    1     INDEX (RANGE SCAN) OF 'IT_CREATE_DT_IDX' (INDEX) (Cost=1
           Card=1)

A function on THE INDEXED COLUMN is obviates the index.


SQL> select * from index_test where trunc(create_dt) = to_date('17-SEP-2000', 'DD-MON-YYYY');


Execution Plan
----------------------------------------------------------
   0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=59 Card=3 Bytes=78
          )

   1    0   TABLE ACCESS (FULL) OF 'INDEX_TEST' (TABLE) (Cost=59 Card=
          3 Bytes=78)
Stephanie Page
Oh well, he deleted his wrong advice. I'm leaving this here though in case someone else decides to post the wrong answer.
Stephanie Page
Didn't read the question properly.
cagcowboy
+3  A: 

You have two queries

select * from view where date = '17-sep-10'
select * from view where date = to_date(...

In the first, the 'date' column in the view is being compared to a character literal. In the second it is being compared to a date.

If the first is working (and quickly), it is possible that the 'date' column in the view is a VARCHAR2 column rather than a date. The fact that you are doing a TO_DATE on a column called current_business_date suggests that you may be using the wrong datatypes.

Do a DESC VIEW in SQL*Plus (or equivalent in whatever tool you use).

Also do an EXPLAIN PLAN for both select * from view where date = '17-sep-10' and select * from view where date = date '2010-09-17'

Gary
I think if the NLS settings are right Oracle might do the date casting to the literal. You might be onto something however - another way to check would be "select * from view where date = to_date('17-sep-10', 'DD-MON-YY')"
dpbradley
I did the explain plan using that query and it runs fast. It only slows down when I use our v_business_day view
Dan
A: 

On the execution plans, it would also be helpful to know on which step the date predicate was being applied.

The actual response time culprit in the second plan is the full scan on POSITIONS. In the first plan we are doing an index range scan using POSITIONS_IDX_01. What columns are in that index? In particular, do any of them relate to the business_date column in the view?

I'm guessing that the v_business_day view is based on PARAMETER_CONTROL, since that seems to be referenced more times in the second plan than in the first. The portions of the second plan that are based entirely on this table have estimated cardinalities of 1, so it does not appear that the problem is that Oracle thinks the subquery might be returning multiple rows (which jives with your statement that adding the condition on ROWNUM to the subquery did not change the performance).

Response to comment: It sounds like the statistics on POSITIONS.BUSINESS_DATE are such that the optimizer can see that the literal date value will be highly selective, but that an arbitrary date value is likely to be highly unselective. You should look into the statistics -- in USER_TABLES, USER_INDEXES, and USER_HISTOGRAMS -- to see if they are out of date and what they indicate about the data distribution of this column.

The simplest way out of this may be to do one query to get the current business date, then insert it as a literal into the query against the complex view.

Dave Costa
positions_idx_01 has columns "BUSINESS_DATE", "SOURCE", and "ACCOUNT_NUMBER". I did try and add an index hint on the 2nd query but that did not help.
Dan
A: 

I'm going to stick my head out and put this down to column stats or skew.

One plan has

|* 57 | TABLE ACCESS BY INDEX ROWID| POSITIONS        | 2432 | 767K| 1549 (1)| 00:00:19 |       
|* 58 |  INDEX RANGE SCAN          | POSITIONS_IDX_01 | 5676 |     |  737 (2)| 00:00:09 |       

The other has

|* 46 |  TABLE ACCESS FULL         | POSITIONS        |  806K| 248M| 365K (3)| 01:13:09 |       

Given the date '17-Sep-2010', Oracle is assuming several thousand rows will be returned. Given another non-specific date, Oracle is assuming a much larger number, so large that the date index is useless. I suspect most of the rows in the table were for the same small number of dates (probably less than a hundred distinct values - but you can look in NUM_DISTINCT in USER_TAB_COLUMNS).

I say were because I think the stats may be out of date. There'll be a LOW_VALUE and HIGH_VALUE on USER_TAB_COLUMNS for that date column in the table (in RAW format, not as actual dates). When faced with a query for a value above the recorded high_value, 10g makes some assumptions. If there are a million rows for a hundred distinct values, it will assume 10,000 rows for each value [in the absence of histograms] but for a value above the HIGH_VALUE it will assume less than 10,000 rows. It gets all statistical in its calculations, so its hard to be precise. But its enough that the database is thinking that rows for Sept 17th are sufficiently small in number as to make it worth using the index.

So there's four things to determine. How many rows are in the table, and what is the distribution over dates. How many rows do the stats indicate are in the table and what do the stats suggest is the distribution over dates.

Gary