Hi Tom
Here is the output using DBMS_XPLAN for the four (4) test cases I've been running.
Many thanks for your assistance.
-gary
==========================================
Run using the function directly:
indgww@jdeprod> host more f42119_func.sql
explain plan for
select count(distinct sduorg) cnt
from proddta.f42119
where sdupmj > proddta.dcdttoju( sysdate -3 )
/
indgww@jdeprod> @f42119_func.sql
Explained.
indgww@jdeprod>
select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
--------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9 | 166K|
| 1 | SORT GROUP BY | | 1 | 9 | |
|* 2 | TABLE ACCESS FULL | F42119 | 517K| 4549K| 166K|
--------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("F42119"."SDUPMJ">"PRODDTA"."DCDTTOJU"(SYSDATE@!-3))
Note: cpu costing is off
15 rows selected.
==========================================
Run using the hard coded number:
indgww@jdeprod> host more f42119_hard.sql
explain plan for
select count(distinct sduorg) cnt
from proddta.f42119
where sdupmj > 107337
/
indgww@jdeprod> @f42119_hard.sql
Explained.
indgww@jdeprod>
select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9 | 12021 (0)|
| 1 | SORT GROUP BY | | 1 | 9 | |
| 2 | TABLE ACCESS BY INDEX ROWID | F42119 | 60396 | 530K| 12021 (0)|
| 3 | BITMAP CONVERSION TO ROWIDS| | | | |
|* 4 | BITMAP INDEX RANGE SCAN | F42119_SDUPMJ_BM | | | |
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("F42119"."SDUPMJ">107337)
filter("F42119"."SDUPMJ">107337)
16 rows selected.
==========================================
Run using the TO_NUMBER( TO_CHAR( <date> )):
indgww@jdeprod> host more f42119_tochar.sql
explain plan for
select count(distinct sduorg) cnt
from proddta.f42119
where sdupmj > to_number('1' || to_char(sysdate -3, 'RRDDD'))
/
indgww@jdeprod> @f42119_tochar.sql
Explained.
indgww@jdeprod>
select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9 | 97147 (0)|
| 1 | SORT GROUP BY | | 1 | 9 | |
| 2 | TABLE ACCESS BY INDEX ROWID | F42119 | 517K| 4549K| 97147 (0)|
| 3 | BITMAP CONVERSION TO ROWIDS| | | | |
|* 4 | BITMAP INDEX RANGE SCAN | F42119_SDUPMJ_BM | | | |
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("F42119"."SDUPMJ">TO_NUMBER('1'||TO_CHAR(SYSDATE@!-3,'RRDDD')))
filter("F42119"."SDUPMJ">TO_NUMBER('1'||TO_CHAR(SYSDATE@!-3,'RRDDD')))
16 rows selected.
==========================================
Run using the function in a scalar query:
indgww@jdeprod> host more f42119_inline.sql
explain plan for
select count(distinct sduorg) cnt
from proddta.f42119
where sdupmj > (select proddta.dcdttoju(sysdate -3) from dual)
/
indgww@jdeprod> @f42119_inline.sql
Explained.
indgww@jdeprod>
select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9 | 97147 (0)|
| 1 | SORT GROUP BY | | 1 | 9 | |
| 2 | TABLE ACCESS BY INDEX ROWID | F42119 | 517K| 4549K| 97147 (0)|
| 3 | BITMAP CONVERSION TO ROWIDS| | | | |
|* 4 | BITMAP INDEX RANGE SCAN | F42119_SDUPMJ_BM | | | |
| 5 | TABLE ACCESS FULL | DUAL | 8168 | | 11 (0)|
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - access("F42119"."SDUPMJ"> (SELECT /*+ */ "PRODDTA"."DCDTTOJU"(SYSDATE@!-3) FROM
"SYS"."DUAL" "DUAL"))
filter("F42119"."SDUPMJ"> (SELECT /*+ */ "PRODDTA"."DCDTTOJU"(SYSDATE@!-3) FROM
"SYS"."DUAL" "DUAL"))
19 rows selected.