dbTalk Databases Forums  

Which is faster? <> or Between

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Which is faster? <> or Between in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Just_Buy
 
Posts: n/a

Default Which is faster? <> or Between - 06-25-2003 , 10:57 AM






Which of the following methods is faster for retrieving records within a date range?

Option A:
Paid_Date >= '01-JAN-2003' AND Paid_Date <= '01-MAR-2003'

Option B:
Paid_Date BETWEEN '01-JAN-2003' AND '01-MAR-2003'

Thanks!

Reply With Quote
  #2  
Old   
Daniel Morgan
 
Posts: n/a

Default Re: Which is faster? <> or Between - 06-25-2003 , 11:12 AM






Just_Buy wrote:

Quote:
Which of the following methods is faster for retrieving records within a date range?

Option A:
Paid_Date >= '01-JAN-2003' AND Paid_Date <= '01-MAR-2003'

Option B:
Paid_Date BETWEEN '01-JAN-2003' AND '01-MAR-2003'

Thanks!
Do your homework on your computer ... not in a usenet group.

It would take you less time, and be substantially less aggravating to run EXPLAIN PLAN
on these two statements than it has been to read this answer and get upset at my
response which doubtless you will choose to do.
--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)




Reply With Quote
  #3  
Old   
Just_Buy
 
Posts: n/a

Default Re: Which is faster? <> or Between - 06-25-2003 , 06:33 PM



My apologies for not being an Oracle expert like yourself. Since I am
not aware of the "EXPLAIN PLAN" syntax I will research this syntax and
conduct some tests. Once completed I will post my findings back to
this Usenet group so others can learn. Please correct me if I'm
wrong, but learning from others is a goal of these Usenet groups.


Daniel Morgan <damorgan (AT) exxesolutions (DOT) com> wrote

Quote:
Just_Buy wrote:

Which of the following methods is faster for retrieving records within a date range?

Option A:
Paid_Date >= '01-JAN-2003' AND Paid_Date <= '01-MAR-2003'

Option B:
Paid_Date BETWEEN '01-JAN-2003' AND '01-MAR-2003'

Thanks!

Do your homework on your computer ... not in a usenet group.

It would take you less time, and be substantially less aggravating to run EXPLAIN PLAN
on these two statements than it has been to read this answer and get upset at my
response which doubtless you will choose to do.

Reply With Quote
  #4  
Old   
Jim Kennedy
 
Posts: n/a

Default Re: Which is faster? <> or Between - 06-25-2003 , 09:51 PM



try it. One word of advice don't do it that way. You are counting on a
particular nls date format. Instead wrap the strings in to_date eg
to_date('01-JAN-2003','dd-mmm-yyyy')
Jim

--
Replace part of the email address: kennedy-down_with_spammers (AT) attbi (DOT) com
with family. Remove the negative part, keep the minus sign. You can figure
it out.
"Just_Buy" <ohbej (AT) hotmail (DOT) com> wrote

Quote:
Which of the following methods is faster for retrieving records within a
date range?

Option A:
Paid_Date >= '01-JAN-2003' AND Paid_Date <= '01-MAR-2003'

Option B:
Paid_Date BETWEEN '01-JAN-2003' AND '01-MAR-2003'

Thanks!



Reply With Quote
  #5  
Old   
Scott Mattes
 
Posts: n/a

Default Re: Which is faster? <> or Between - 06-26-2003 , 08:49 AM



I think that it will matter more if you have indexes and such on the table
in question than on the method that you use to do the compare. I ran the
following test (on 8.1.7 via remote sqlnet hookup) and for the 10,000
iterations the difference was less than 20 - with between being slower.

=========
DECLARE
answer INTEGER;

l_date DATE;

l_first DATE;
l_end DATE;

start_time binary_integer;
end_time binary_integer;

BEGIN
l_date := SYSDATE;

l_first := To_Date( '01-JAN-2003', 'dd-mon-yyyy' );
l_end := To_Date( '01-MAR-2003', 'dd-mon-yyyy' );

start_time := Dbms_Utility.get_time;

FOR l_looper in 1..10000
loop
SELECT 1
INTO answer
FROM dual
WHERE 1 = 1
OR ( l_date >= l_first
AND l_Date <= l_end
);
END LOOP;

end_time := Dbms_Utility.get_time;

Dbms_Output.put( '">= <=" elapsed=' );
Dbms_Output.put_line( end_time - start_time );

start_time := Dbms_Utility.get_time;

FOR l_looper in 1..10000
loop
SELECT 1
INTO answer
FROM dual
WHERE 1 = 1
OR ( l_date between l_first AND l_end
);
END LOOP;

end_time := Dbms_Utility.get_time;

Dbms_Output.put( '"between" elapsed=' );
Dbms_Output.put_line( end_time - start_time );

END;
=========
"Just_Buy" <ohbej (AT) hotmail (DOT) com> wrote

Quote:
My apologies for not being an Oracle expert like yourself. Since I am
not aware of the "EXPLAIN PLAN" syntax I will research this syntax and
conduct some tests. Once completed I will post my findings back to
this Usenet group so others can learn. Please correct me if I'm
wrong, but learning from others is a goal of these Usenet groups.


Daniel Morgan <damorgan (AT) exxesolutions (DOT) com> wrote

Just_Buy wrote:

Which of the following methods is faster for retrieving records within
a date range?

Option A:
Paid_Date >= '01-JAN-2003' AND Paid_Date <= '01-MAR-2003'

Option B:
Paid_Date BETWEEN '01-JAN-2003' AND '01-MAR-2003'

Thanks!

Do your homework on your computer ... not in a usenet group.

It would take you less time, and be substantially less aggravating to
run EXPLAIN PLAN
on these two statements than it has been to read this answer and get
upset at my
response which doubtless you will choose to do.



Reply With Quote
  #6  
Old   
Jim Kennedy
 
Posts: n/a

Default Re: Which is faster? <> or Between - 06-26-2003 , 09:58 AM



You should be converting the constants in both cases to dates by using
to_date. It would be very efficient and the code would be less prone to
breaking if he did that.
Jim

--
Replace part of the email address: kennedy-down_with_spammers (AT) attbi (DOT) com
with family. Remove the negative part, keep the minus sign. You can figure
it out.
"M" <noreply (AT) noreply (DOT) com> wrote

Quote:
It seems to me that the 'between' should work faster, as long as you don't
have something like to_char, to_date, etc.

Correct me if I was wrong.

"Just_Buy" <ohbej (AT) hotmail (DOT) com> wrote in message
news:65275ae5.0306250757.b859f09 (AT) posting (DOT) google.com...
Which of the following methods is faster for retrieving records within a
date range?

Option A:
Paid_Date >= '01-JAN-2003' AND Paid_Date <= '01-MAR-2003'

Option B:
Paid_Date BETWEEN '01-JAN-2003' AND '01-MAR-2003'

Thanks!





Reply With Quote
  #7  
Old   
Daniel Morgan
 
Posts: n/a

Default Re: Which is faster? <> or Between - 06-26-2003 , 10:55 AM



Just_Buy wrote:

Quote:
My apologies for not being an Oracle expert like yourself. Since I am
not aware of the "EXPLAIN PLAN" syntax I will research this syntax and
conduct some tests. Once completed I will post my findings back to
this Usenet group so others can learn. Please correct me if I'm
wrong, but learning from others is a goal of these Usenet groups.

Daniel Morgan <damorgan (AT) exxesolutions (DOT) com> wrote

Just_Buy wrote:

Which of the following methods is faster for retrieving records within a date range?

Option A:
Paid_Date >= '01-JAN-2003' AND Paid_Date <= '01-MAR-2003'

Option B:
Paid_Date BETWEEN '01-JAN-2003' AND '01-MAR-2003'

Thanks!

Do your homework on your computer ... not in a usenet group.

It would take you less time, and be substantially less aggravating to run EXPLAIN PLAN
on these two statements than it has been to read this answer and get upset at my
response which doubtless you will choose to do.
You missed the point. Everyone can run EXPLAIN PLAN. And what they will learn about is their specific
system with their specific data. It is not necessarily transferrable to anyone else on a different system
with
different data.

So by all means share ... but don't expect that the next time you do an application the result from this one
will apply to the next.
--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)




Reply With Quote
  #8  
Old   
Paul Dixon
 
Posts: n/a

Default Re: Which is faster? <> or Between - 06-30-2003 , 04:22 AM




"Daniel Morgan" <damorgan (AT) exxesolutions (DOT) com> wrote

Quote:
You missed the point. Everyone can run EXPLAIN PLAN. ...
Daniel,

that's not strictly true. To run EXPLAIN PLAN a user must have the necessary
priveleges to either access an existing "PLAN TABLE" or to create one of
thier own. These priveleges aren't automatically granted to every user !!

Paul Dixon




Reply With Quote
  #9  
Old   
Daniel Morgan
 
Posts: n/a

Default Re: Which is faster? <> or Between - 06-30-2003 , 11:07 AM



Paul Dixon wrote:

Quote:
"Daniel Morgan" <damorgan (AT) exxesolutions (DOT) com> wrote in message
news:3EFB1781.BAA7CC10 (AT) exxesolutions (DOT) com...
You missed the point. Everyone can run EXPLAIN PLAN. ...

Daniel,

that's not strictly true. To run EXPLAIN PLAN a user must have the necessary
priveleges to either access an existing "PLAN TABLE" or to create one of
thier own. These priveleges aren't automatically granted to every user !!

Paul Dixon
Necessary privileges? What privileges? There is no privilege associated with
EXPLAIN PLAN.

Now if you don't have CREATE TABLE that could be a problem. But if you don't
have CREATE TABLE you aren't a developer.
--
Daniel Morgan
http://www.outreach.washington.edu/e...ad/oad_crs.asp
damorgan@x.washington.edu
(replace 'x' with a 'u' to reply)




Reply With Quote
  #10  
Old   
Pablo Sanchez
 
Posts: n/a

Default Re: Which is faster? <> or Between - 06-30-2003 , 01:11 PM



Daniel Morgan <damorgan (AT) exxesolutions (DOT) com> wrote in
news:3F006029.ECE34F77 (AT) exxesolutions (DOT) com:

Quote:
Now if you don't have CREATE TABLE that could be a problem. But if
you don't have CREATE TABLE you aren't a developer.
A shame that you have to give a developer CREATE TABLE on a production
machine to replicate the problem that 'only shows up on a production
instance.'
--
Pablo Sanchez, Blueoak Database Engineering
http://www.blueoakdb.com


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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.