Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««678910

The Cost of Function Use In A Where Clause Expand / Collapse
Author
Message
Posted Wednesday, March 5, 2008 8:01 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, November 3, 2008 8:55 PM
Points: 1, Visits: 5
Would it be the time itself is pretty much an unique value already?
So it don't produce a good index on it?
Post #464860
Posted Thursday, March 6, 2008 3:53 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, May 29, 2014 12:39 PM
Points: 110, Visits: 495
Sorry Michaell,

I dont understand the question here...



GAJ


Gregory A Jackson MBA, CSM
Post #464864
Posted Thursday, March 6, 2008 4:07 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 3:51 PM
Points: 36,959, Visits: 31,469
Michaell (3/5/2008)
Would it be the time itself is pretty much an unique value already?
So it don't produce a good index on it?


Absolutely not... the more unique a value it is, the better an index can be made from it.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #464868
Posted Thursday, March 6, 2008 9:12 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 3:51 PM
Points: 36,959, Visits: 31,469
Just a test... please ignore...

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #465261
Posted Thursday, March 6, 2008 11:00 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 3:51 PM
Points: 36,959, Visits: 31,469
Just another test... please ignore.

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #465379
Posted Thursday, March 6, 2008 11:23 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, August 13, 2008 11:30 PM
Points: 10, Visits: 23
Greg,

How can we improve the following query?
-------------------------
--------------------------
WHERE
filter 1
AND filter 2
AND CONVERT(DATETIME,A.DateValue) BETWEEN (GetDate()-30) AND (GetDate()+30)

Column DateValue in table A has datatype (varchar/nvarchar) but datetime.

Thanks in advance.

Rishi
Post #465017
Posted Thursday, March 6, 2008 11:33 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, August 13, 2008 11:30 PM
Points: 10, Visits: 23
Many times we need to use function 'MAX' in 'Select' clause specially for dates. Does anyone has a thought on different approach.

For example

select max(a.closedate) as closedate, a.offerid
from a inner join b on a.id =b.id
inner join c on b.xx = c.xx
group by a.offerid


Thanks,

Rishi
Post #465019
Posted Thursday, March 6, 2008 12:29 PM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 4:11 PM
Points: 15,646, Visits: 28,027
Rishi Girdhar (3/6/2008)
Many times we need to use function 'MAX' in 'Select' clause specially for dates. Does anyone has a thought on different approach.

For example

select max(a.closedate) as closedate, a.offerid
from a inner join b on a.id =b.id
inner join c on b.xx = c.xx
group by a.offerid


Thanks,

Rishi


We did a series of tests and found, depending on how you do your indexing, TOP actually works a bit better than MAX. You have to include an ORDER BY and get the ASC/DESC right.


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #465038
Posted Thursday, March 6, 2008 11:46 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, August 13, 2008 11:30 PM
Points: 10, Visits: 23
Thanks Grant,

I will try with TOP and ORDER BY and see the difference.

Thanks again,
Rishi
Post #465651
« Prev Topic | Next Topic »

Add to briefcase «««678910

Permissions Expand / Collapse