Unix Technical Forum

Slow query on date field via views

This is a discussion on Slow query on date field via views within the Oracle Miscellaneous forums, part of the Oracle Database category; --> I have several views with unions, outer joints and calculations that later combine to find a "final" report view. ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database > Oracle Miscellaneous

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 10:26 AM
AcCeSsDeNiEd
 
Posts: n/a
Default Slow query on date field via views

I have several views with unions, outer joints and calculations that later combine to find a "final"
report view.
This was to make things easier for the web-based report programmer to just pull the values from this
view.

If I query the view by the id/index/primary_key, the view runs fine (about 3secs)

e.g: Select *
from final_view
where Id_Index in (123, 456, 789)

However, when the view is queried by dates, it is slow.
More like impossible actually 'cos the temp table space gets filled up (32GB!) and oracle returns an
error about
being unable to extend.

E.g: Select *
from final_view
where Submission_Date=to_date('01-01-2005', 'dd-mm-yyyy')


I tried indexing the Sub_Date but it didn't help.

But if I run the query directly on the table in question (with the sub_date), the query works fine &
fast,
with or without the indexing.

Anyone got any pointers?

I'm using oracle 9i.
And the 3 big tables which the view taps on have about 100,000 records each.


Thanks



To e-mail, remove the obvious
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 10:26 AM
Sybrand Bakker
 
Posts: n/a
Default Re: Slow query on date field via views

On Wed, 10 May 2006 10:07:09 +0800, AcCeSsDeNiEd
<dillon@SpamMinuSaccessdenied.darktech.org> wrote:

>I have several views with unions, outer joints and calculations that later combine to find a "final"
>report view.
>This was to make things easier for the web-based report programmer to just pull the values from this
>view.
>
>If I query the view by the id/index/primary_key, the view runs fine (about 3secs)
>
>e.g: Select *
> from final_view
> where Id_Index in (123, 456, 789)
>
>However, when the view is queried by dates, it is slow.
>More like impossible actually 'cos the temp table space gets filled up (32GB!) and oracle returns an
>error about
>being unable to extend.
>
>E.g: Select *
> from final_view
> where Submission_Date=to_date('01-01-2005', 'dd-mm-yyyy')
>
>
>I tried indexing the Sub_Date but it didn't help.
>
>But if I run the query directly on the table in question (with the sub_date), the query works fine &
>fast,
>with or without the indexing.
>
>Anyone got any pointers?
>
>I'm using oracle 9i.
>And the 3 big tables which the view taps on have about 100,000 records each.
>
>
>Thanks
>
>
>
>To e-mail, remove the obvious



Did you get the explain plans and compare them?
Please get the explain plans and post them here.

--
Sybrand Bakker, Senior Oracle DBA
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 10:28 AM
AcCeSsDeNiEd
 
Posts: n/a
Default Re: Slow query on date field via views - weekly_r_view_plan_table.xls (0/1)

Sybrand Bakker <post...@sybrandb.demon.nl> wrote:

>Did you get the explain plans and compare them?
>Please get the explain plans and post them here.


>--
>Sybrand Bakker, Senior Oracle DBA


Ok, after much fiddling around and running sqlanalyze I was able to optimize the query pretty well.
It told me to use a "union all" instead of "union". I hope I don't end up with dupe rows.
That did help pretty much.

However, it still took me 25 secs to run the below query:

Select w.*
from client.weekly_report_details w
where w.submission_date between to_date('17-Apr-2005', 'DD-MON-YYYY') and to_date('30-Apr-2005',
'DD-MON-YYYY')
and w.adv_id=42

If I use the index then it runs about 2 secs:

Select w.*
from client.weekly_report_details w
where w.submission_date between to_date('17-Apr-2005', 'DD-MON-YYYY') and to_date('30-Apr-2005',
'DD-MON-YYYY')
and w.policy_id in (63771, 63923, 63924)

I found more nasties in the jsp report the vendor wrote.
He was using to_char() on the date fields.

My plan table seems to be pretty big
I have no idea how to read it.

I hope a small binary does not irk people here

Thanks



To e-mail, remove the obvious
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-08-2008, 10:29 AM
AcCeSsDeNiEd
 
Posts: n/a
Default Re: Slow query on date field via views - weekly_r_view_plan_table.xls (0/1)

Sybrand Bakker <post...@sybrandb.demon.nl> wrote:

>Did you get the explain plans and compare them?
>Please get the explain plans and post them here.


>--
>Sybrand Bakker, Senior Oracle DBA


Ok, after much fiddling around and running sqlanalyze I was able to optimize the query pretty well.
It told me to use a "union all" instead of "union". I hope I don't end up with dupe rows.
That did help pretty much.

However, it still took me 25 secs to run the below query:

Select w.*
from client.weekly_report_details w
where w.submission_date between to_date('17-Apr-2005', 'DD-MON-YYYY') and to_date('30-Apr-2005',
'DD-MON-YYYY')
and w.adv_id=42

If I use the index then it runs about 2 secs:

Select w.*
from client.weekly_report_details w
where w.submission_date between to_date('17-Apr-2005', 'DD-MON-YYYY') and to_date('30-Apr-2005',
'DD-MON-YYYY')
and w.policy_id in (63771, 63923, 63924)

I found more nasties in the jsp report the vendor wrote.
He was using to_char() on the date fields.

My plan table seems to be pretty big
I have no idea how to read it.

I hope a small binary does not irk people here

Thanks



To e-mail, remove the obvious
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:15 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com