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 «««12345

Is It Time To Clear Out Those Quirky Functions? Expand / Collapse
Author
Message
Posted Monday, July 14, 2014 3:33 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 10:23 PM
Points: 795, Visits: 1,548
This may be what GPO noted previously.


Yep. Me and many many others.




One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important.
Bertrand Russell
Post #1592362
Posted Monday, July 14, 2014 3:40 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 10:23 PM
Points: 795, Visits: 1,548
@GoofyGuy
PRETTIFY('phil factor')


Hahahahaha. Maybe there's a reason he only allows us to envisage him through some obscure sepia photo.




One of the symptoms of an approaching nervous breakdown is the belief that one's work is terribly important.
Bertrand Russell
Post #1592364
Posted Monday, July 14, 2014 3:48 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 1:55 PM
Points: 36,749, Visits: 31,197
Andy Warren (7/11/2014)
Jeff, did I just see you plug for Access?


Heh... not quite. I figure if even lowly Access can have an incredible and easy to use PIVOT function, why not SQL Server?


--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 #1592367
Posted Monday, July 14, 2014 3:53 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 1:55 PM
Points: 36,749, Visits: 31,197
Alan.B (7/14/2014)
Jeff Moden (7/10/2014)
Alan.B (7/10/2014)
Phil, you can make this more than twice as fast by turning it into an inline table value function like this:


To that, I say... are you sure? Please read the following article before you answer that question.
http://www.sqlservercentral.com/articles/T-SQL/91724/


I should have posted a different test harness but I was basing that statement on the fact that - on my system the original function runs for 10-11 seconds (11 with results on, 10 with results off). The itvf version runs for 3-5 seconds (3 with results off). Those were the times I got just by just highlighting the code and hitting F5.

If I measure the results like this:

DECLARE @Result char(4);
--===== Begin measuring duration using GETDATE
DECLARE @StartTime DATETIME;
SELECT @StartTime = GETDATE();
--===== Test the code using the "throw-away" variable

PRINT char(13)+'lefttrim:'
SELECT @result = dbo.lefttrim(string)
FROM #test;

--===== "Stop the timer" and report the duration
PRINT DATEDIFF(ms,@StartTime,GETDATE());
GO

DECLARE @Result char(4);
--===== Begin measuring duration using GETDATE
DECLARE @StartTime DATETIME;
SELECT @StartTime = GETDATE();
--===== Test the code using the "throw-away" variable

PRINT char(13)+'itvf_lefttrim:'
SELECT @result = x.string
FROM #test
CROSS APPLY dbo.itvf_LeftTrim(string) x;

--===== "Stop the timer" and report the duration
PRINT DATEDIFF(ms,@StartTime,GETDATE());
GO

Results:

lefttrim:
10703

itvf_lefttrim:
3466


This is on my laptop (4X) 2.6 ghz, 16gb ram, SQL 2014 Ent.


Now that's what I'm talking about. Something that others can run and something that doesn't use SET STATISTICS on a Scalar Funtion. Thanks, Alan.


--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 #1592370
Posted Monday, July 14, 2014 3:59 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 1:55 PM
Points: 36,749, Visits: 31,197
Phil Factor (7/11/2014)
@Alan.B
After reading your comment, I've nervously put the routine in a test harness. It clocked at 0.054 Ms. per execution. I have to say that when I'm optimizing, I go after bigger fish!


It's just such small-fry that used to choke the server I took over because there were many such small fish that got executed hundreds of millions of times per day. If you consider the overall improvement is 3:1, that's not bad especially considering the number of executions over the course of the day.


--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 #1592372
Posted Tuesday, July 15, 2014 7:19 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 10:04 AM
Points: 1, Visits: 9
These quirky functions keep us TSQL developers special. The ISNUMERIC tests a field, and CAST converts it if you want.
CASE ISNUMERIC(LEFT(a.[CHBID], 7))
WHEN 1
THEN CAST(LEFT(a.[CHBID], 7) AS INT)
ELSE 0
END AS CHBID
Post #1592548
Posted Tuesday, July 15, 2014 7:52 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Monday, July 21, 2014 4:34 PM
Points: 211, Visits: 819
Jeff Moden (7/14/2014)


It's just such small-fry that used to choke the server I took over because there were many such small fish that got executed hundreds of millions of times per day.


Most .NET apps I see are spamming the database with thousands of calls a second loading and reloading data; whereby the programmers don't even know why it's happening and can't stop it.

So yeah, amen. Tiny improvements (admittedly on known hot spots) can have big improvements
Post #1592573
Posted Friday, July 18, 2014 10:06 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 2:10 PM
Points: 258, Visits: 597
We got hit by ISNUMERIC early. It will convert text that happens to be valid hexadecimal into a positive hit. So we went to PATINDEX to find values that were numeric. So in the background it does conversion checks.
Post #1594140
Posted Tuesday, July 22, 2014 7:49 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 11:19 AM
Points: 5,181, Visits: 2,798
Perhaps some kind of deprecation warning (with the ability to locally disable - equivalent of an old C styled # command) would be beneficial for script updates. I completely agree that any kind of deprecation should be 2 stepped just like Java and .NET i.e. first marked as deprecated in a release (with warnings raised) then a standard minimum number of releases occur before removal is even allowed, if at all.

Gaz

-- Stop your grinnin' and drop your linen...they're everywhere!!!
Post #1595087
Posted Tuesday, July 22, 2014 12:05 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 1:55 PM
Points: 36,749, Visits: 31,197
JustMarie (7/18/2014)
We got hit by ISNUMERIC early. It will convert text that happens to be valid hexadecimal into a positive hit. So we went to PATINDEX to find values that were numeric. So in the background it does conversion checks.


I know I'm being a bit pedantic here but you didn't "get hit" by ISNUMERIC... you used ISNUMERIC incorrectly. I'll admit that the MS documentation isn't in-your-face clear about what it doesn't do (it was never meant to be an IsAllDigits function), but it does state exactly what it does do.


--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 #1595220
« Prev Topic | Next Topic »

Add to briefcase «««12345

Permissions Expand / Collapse