Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Full table scan of a partitioned table.

Posted on 2013-01-05
5
Medium Priority
?
649 Views
Last Modified: 2013-01-13
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?
0
Comment
Question by:gram77
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Author Comment

by:gram77
ID: 38746514
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');

why?
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
ID: 38747365
its simple because the partition is on date column not on to_date(date, 'dd-mm-yyyy')
0
 
LVL 35

Accepted Solution

by:
Mark Geerlings earned 800 total points
ID: 38747368
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')
0
 
LVL 38

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 400 total points
ID: 38749202
don't do a calculation on a column with an index (or partitioned index)
if you want to the optimizer to use the index
0
 
LVL 28

Assisted Solution

by:Naveen Kumar
Naveen Kumar earned 800 total points
ID: 38749995
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.

http://www.akadia.com/services/ora_function_based_index_2.html
http://psoug.org/snippet/INDEXES-Function-Based-Index_804.htm
www.oracle-base.com/articles/8i/function-based-indexes.php
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
Via a live example, show how to take different types of Oracle backups using RMAN.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question