Oracle Function based index

Posts   
 
    
samvarg
User
Posts: 25
Joined: 26-Feb-2010
# Posted on: 14-Oct-2010 21:50:21   

I have a function based index on a column like TRUNC(DATECREATED). When I use the predicate expression do I have to do something to force this index. When I did the DB trace the generated SQL didn't use the index the SQL was like

"DATECREATED" BETWEEN :Datecreated2 AND :Datecreated3

. So it didn't use the index.

Thanks Sam

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 14-Oct-2010 21:59:12   

Generally, the generated SQL will not include the name of the indexes used - the RDBMs will select what it thinks is the best index for the query at the time that it processes the query. This can usually be seen by examing the query execution plan. I know this is easy do to in SQL Server - I'm assuming Oracle has something similar?

If you examine the execution plan, does it show your index being used ?

Matt

samvarg
User
Posts: 25
Joined: 26-Feb-2010
# Posted on: 14-Oct-2010 22:07:01   

In the execution plan this index doesn't show.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 14-Oct-2010 22:22:06   

This means the the query optimizer does not think that the index is worth using for the query - why do you think the index should be used..?

Matt

samvarg
User
Posts: 25
Joined: 26-Feb-2010
# Posted on: 14-Oct-2010 22:41:10   

Because When I take the query and run directly on oracle and if I use trunc(datecreated) it uses the index. But if I just use date created then it doesn't use the index.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Oct-2010 05:05:04   

As Matt said, that is a decision of Oracle SQL Query Optimizer. LLBLGen just generate the sql for you.

What you can do is use a DBFunctionCall so include the TRUNC function in the predicate so your query would use the involved index.

David Elizondo | LLBLGen Support Team
samvarg
User
Posts: 25
Joined: 26-Feb-2010
# Posted on: 18-Oct-2010 16:57:32   

Thanks.

could you please let me know how to use TRUNC function in the predicate.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-Oct-2010 17:15:15   
samvarg
User
Posts: 25
Joined: 26-Feb-2010
# Posted on: 18-Oct-2010 21:32:20   

Since the query return multiple records. I did a storedproc and then I was able to put the TRUNC in the where condition. so now I a able to use the index.

I am using WCF. I was trying to get the data to DataReader from the procedure but since DataReader is not serializable I can't use. I know I can use DataSet. but its heavy.

What is your suggestion on this. which is the best approach to get the results of a stored proc and transfer data in WCF.

thanks Sam

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Oct-2010 04:21:14   
David Elizondo | LLBLGen Support Team
samvarg
User
Posts: 25
Joined: 26-Feb-2010
# Posted on: 19-Oct-2010 21:08:35   

Excellant! Thank you for all your help.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 19-Oct-2010 21:40:08   

No problem, we're always happy to help.

Matt