Full table scan of a partitioned table.

I have a table partitioned by date.

I have a select statement on which the oracle optimizer decides to do  a full table scan  across all partitions why?
Who is Participating?
Mark GeerlingsConnect With a Mentor Database AdministratorCommented:
The optimizer will do a full-table scan instead of a more-efficient partition- based scan if the SQL statement (or query) does not provide a value that matches the partition key column, of if the SQL statement or query applies an operator (like: to_date, to_char, upper, trunc, etc.) on the partition key column.

It is not clear from your second comment what the word "date" refers to in your two examples.  Does your table actually have a column named "date"?  That would be unusual (and not recommended).  What is the actual name of the partition key column in your table?

Also, it is not clear from your examples what "v_date" is.  I'm guessing that represents a variable.

If your table has a column named "date_created" for example, and this is defined as a "date" (and not "varchar2" or "number", etc.) and if the table is partitioned by range on this column, then a query like this should use only one of the table's partitions:

select *
from my_table
where date_created = to_date('&v_date','dd-mm-yyyy')

But a query like this will use a full-table scan (of all partitions):
select *
from my_table
where trunc(date_created) = to_date('&v_date','dd-mm-yyyy')
gram77Author Commented:
select *
from mytable
where to_date(date, 'dd-mm-yyyy') = to_date(v_date, 'dd-mm-yyyy');

However, the optimiser decides to do a partition scan on the following statement:

select *
from mytable
where date = to_date(v_date, 'dd-mm-yyyy');

Wasim Akram ShaikCommented:
its simple because the partition is on date column not on to_date(date, 'dd-mm-yyyy')
Geert GConnect With a Mentor Oracle dbaCommented:
don't do a calculation on a column with an index (or partitioned index)
if you want to the optimizer to use the index
Naveen KumarConnect With a Mentor Production Manager / Application Support ManagerCommented:
If at all you need some calculation or function on a column ( for a genuine reason ) and at the same time you want your optimizer to use indexes then you will have to create functional indexes.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.