Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 25th, 2012, 02:44 AM
gregorio.palama gregorio.palama is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 14 gregorio.palama User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 52 m 49 sec
Reputation Power: 0
Why a certain date makes query faster

Hello to all.

I have a query with a few tables in join, and I filter data with something like

where mytable.initial_date > sysdate-30

If I use any date, it takes about 5 seconds to run, but if I use

to_date('01010001','ddmmrrrr')

instead of any other dates, it takes just a few milliseconds.
Now, it's just a curiosity, but why that date makes the query VERY fast? Does Oracle treat it in some special way? Maybe it knows every date is greatest than that date and doesn't consider the filter?

Thanks for the answers

Reply With Quote
  #2  
Old May 25th, 2012, 02:07 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
You should examine the Explain Plan for each version,
that should give you the answer.

If you want to improve performance, review questions like.
Is the column indexed?
Are statistics up to date?
What is the cardinality of the column?
Comments on this post
medialint agrees!

Reply With Quote
  #3  
Old May 28th, 2012, 02:15 AM
gregorio.palama gregorio.palama is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 14 gregorio.palama User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 52 m 49 sec
Reputation Power: 0
The execution plan for both versions is the same, that's why I am confused. The column is not indexed, statistics are up to date and cardinality is the same for both versions of the query.

Reply With Quote
  #4  
Old May 29th, 2012, 12:41 AM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Quote:
The execution plan for both versions is the same

That does seem odd.
I don't mean to sound patronizing; but are you sure a new Explain Plan was generated?

If the column is not indexed then I don't think statistics or cardinality will come into play;
but someone may know better (someone always does ).

Have you tried using the current date - 30 instead and seeing what you get?
e.g.
SQL Code:
Original - SQL Code
  1. WHERE mytable.initial_date > to_date('04292012','ddmmrrrr')
Comments on this post
gregorio.palama disagrees: that's exactly what made me open the thread...

Reply With Quote
  #5  
Old May 29th, 2012, 03:01 AM
gregorio.palama gregorio.palama is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 14 gregorio.palama User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 52 m 49 sec
Reputation Power: 0
that's exactly why I opened the thread: I've used two different dates, one is to_date('01010001','ddmmrrrr'), the second one is any other different date.

I know it is odd the execution plan is exactly the same, and that's why it made me curious to know what's behind this different times of execution..

Reply With Quote
  #6  
Old May 29th, 2012, 02:53 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Quote:
gregorio.palama disagrees: that's exactly what made me open the thread...

Actually, it is not!

This is how you opened the thread
Code:
where mytable.initial_date > sysdate-30


While this may seem trivial, when you are trying to diagnose some strange behavior,
it is very important to eliminate all variations, however slight.

Clive

Reply With Quote
  #7  
Old May 29th, 2012, 03:11 PM
gregorio.palama gregorio.palama is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 14 gregorio.palama User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 52 m 49 sec
Reputation Power: 0
Quote:
Originally Posted by clivew
Actually, it is not!

This is how you opened the thread
Code:
where mytable.initial_date > sysdate-30


While this may seem trivial, when you are trying to diagnose some strange behavior,
it is very important to eliminate all variations, however slight.

Clive


I'm sorry Clive, but my initial post clearly says

Quote:
If I use any date, it takes about 5 seconds to run


and "any" includes sysdate-30, but to_date('10102012','mmddrrrr') and to_date('12122011','mmddrrrr') too!

Anyways, I don't really want to discuss what my initial post was, since I think the strange behavior seems to be very clear to me..

The only thing that is not clear is the reason of that behavior!

Reply With Quote
  #8  
Old May 29th, 2012, 03:28 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Lets just agree to differ

Hope you find your solution.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Why a certain date makes query faster

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap