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 «««23456»»»

Patindex Expand / Collapse
Author
Message
Posted Saturday, September 13, 2008 4:49 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 6:23 AM
Points: 35,772, Visits: 32,445
Now you're scaring me! :P I wonder if VM's have a problem that way? I've gotta test this at work on Monday... we have some identical boxes some of which have been VM'd and some not.

Or, maybe it's a simple as parallelism... my box is a single CPU... could you add the MAXDOP 1 option to the first "group" of SELECTs and post the output from that?


--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 #569091
Posted Saturday, September 13, 2008 5:26 PM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Thursday, November 27, 2014 1:56 AM
Points: 998, Visits: 6,478
hmm.. With (MAXDOP=1)


for SQL 2005



********************************************************************************
Found, no index
********************************************************************************
===== Far Right =====
--------------CharIndex

SQL Server Execution Times:
CPU time = 8640 ms, elapsed time = 5027 ms.
--------------PatIndex %aa%

SQL Server Execution Times:
CPU time = 8750 ms, elapsed time = 4993 ms.
--------------PatIndex %aa

SQL Server Execution Times:
CPU time = 8750 ms, elapsed time = 5034 ms.
--------------Right

SQL Server Execution Times:
CPU time = 703 ms, elapsed time = 427 ms.
--------------Substring

SQL Server Execution Times:
CPU time = 735 ms, elapsed time = 418 ms.
--------------Like %aa%

SQL Server Execution Times:
CPU time = 8594 ms, elapsed time = 4922 ms.
--------------Like %aa

SQL Server Execution Times:
CPU time = 8999 ms, elapsed time = 5404 ms.
================================================================================
===== Far Left =====
--------------CharIndex

SQL Server Execution Times:
CPU time = 1063 ms, elapsed time = 675 ms.
--------------PatIndex %aa%

SQL Server Execution Times:
CPU time = 1109 ms, elapsed time = 724 ms.
--------------PatIndex aa%

SQL Server Execution Times:
CPU time = 8969 ms, elapsed time = 5400 ms.
--------------Left

SQL Server Execution Times:
CPU time = 719 ms, elapsed time = 731 ms.
--------------Substring

SQL Server Execution Times:
CPU time = 719 ms, elapsed time = 735 ms.
--------------Like %aa%

SQL Server Execution Times:
CPU time = 968 ms, elapsed time = 610 ms.
--------------Like aa%

SQL Server Execution Times:
CPU time = 9000 ms, elapsed time = 5226 ms.
================================================================================
===== Middle =====
--------------CharIndex

SQL Server Execution Times:
CPU time = 4610 ms, elapsed time = 2836 ms.
--------------PatIndex %aa%

SQL Server Execution Times:
CPU time = 4874 ms, elapsed time = 2850 ms.
--------------Substring

SQL Server Execution Times:
CPU time = 813 ms, elapsed time = 479 ms.
--------------Like %aa%

SQL Server Execution Times:
CPU time = 4750 ms, elapsed time = 2856 ms.
================================================================================


SQL 2008


********************************************************************************
Found, no index
********************************************************************************
===== Far Right =====
--------------CharIndex

SQL Server Execution Times:
CPU time = 11657 ms, elapsed time = 9175 ms.
--------------PatIndex %aa%

SQL Server Execution Times:
CPU time = 11281 ms, elapsed time = 7517 ms.
--------------PatIndex %aa

SQL Server Execution Times:
CPU time = 10219 ms, elapsed time = 5786 ms.
--------------Right

SQL Server Execution Times:
CPU time = 859 ms, elapsed time = 493 ms.
--------------Substring

SQL Server Execution Times:
CPU time = 718 ms, elapsed time = 438 ms.
--------------Like %aa%

SQL Server Execution Times:
CPU time = 10548 ms, elapsed time = 5706 ms.
--------------Like %aa

SQL Server Execution Times:
CPU time = 10234 ms, elapsed time = 5853 ms.
================================================================================
===== Far Left =====
--------------CharIndex

SQL Server Execution Times:
CPU time = 1109 ms, elapsed time = 711 ms.
--------------PatIndex %aa%

SQL Server Execution Times:
CPU time = 1048 ms, elapsed time = 745 ms.
--------------PatIndex aa%

SQL Server Execution Times:
CPU time = 10577 ms, elapsed time = 5558 ms.
--------------Left

SQL Server Execution Times:
CPU time = 781 ms, elapsed time = 812 ms.
--------------Substring

SQL Server Execution Times:
CPU time = 812 ms, elapsed time = 818 ms.
--------------Like %aa%

SQL Server Execution Times:
CPU time = 1001 ms, elapsed time = 660 ms.
--------------Like aa%

SQL Server Execution Times:
CPU time = 10609 ms, elapsed time = 5585 ms.
================================================================================
===== Middle =====
--------------CharIndex

SQL Server Execution Times:
CPU time = 5454 ms, elapsed time = 3206 ms.
--------------PatIndex %aa%

SQL Server Execution Times:
CPU time = 5874 ms, elapsed time = 3229 ms.
--------------Substring

SQL Server Execution Times:
CPU time = 797 ms, elapsed time = 450 ms.
--------------Like %aa%

SQL Server Execution Times:
CPU time = 5531 ms, elapsed time = 3205 ms.
================================================================================

I have three more machines with sql 05 on them in my house, and tommorow I'll test this code on them too just to see what will happen. I could do it now but it is 2 AM here ;)


-------------------------------------------------------------
"It takes 15 minutes to learn the game and a lifetime to master"
"Share your knowledge. It's a way to achieve immortality."


Post #569099
Posted Saturday, September 13, 2008 6:45 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 6:23 AM
Points: 35,772, Visits: 32,445
Wow... even those seem pretty long. Maybe it's cache on my machine. I've not checked but it was advertised as a "server quality" mother board with lot's of cache... I bought it because a friend at one of the local stores gave me a deal on it. I'll take a look at the BIOS and see what's going on.

--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 #569109
Posted Saturday, September 13, 2008 7:46 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Thursday, November 27, 2014 4:23 AM
Points: 20,584, Visits: 9,624
Hey Jeff I found the problem with the test machine... it's just crappy.

I reran the test with 10 000 rows (100 times less data), and it still ran only 110 times faster than the original test.

So that's all she wrote :P.
Post #569120
Posted Saturday, September 13, 2008 9:50 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 6:23 AM
Points: 35,772, Visits: 32,445
Heh... "Crap happens". :P

--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 #569134
Posted Monday, September 15, 2008 1:12 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Monday, December 15, 2014 4:15 AM
Points: 5,478, Visits: 1,402
The article and discussion both are superb...


Post #569264
Posted Monday, September 15, 2008 8:46 AM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, December 5, 2014 2:22 PM
Points: 1,586, Visits: 1,860
Jeff, thanks for that great test script. I like your code for building 1,000,000 row table. I'm saving this code for reference.

Thanks for pointing out how much more efficient LEFT is than LIKE or CHARINDEX. (I knew that, but wasn't thinking about it.)
My original WHERE clause:
WHERE Address LIKE 'XX%' would be much faster as
WHERE LEFT(Address,2) = 'XX'

It's easy to get caught up in
WHERE Col1 LIKE '%aa%'
OR Col1 LIKE '%bb%
OR Col1 LIKE 'xx%'

Maybe this is where LIKE gets the bad rap - when the code should be using LEFT() instead.
Post #569514
Posted Monday, September 15, 2008 10:05 AM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Today @ 6:23 AM
Points: 35,772, Visits: 32,445
Carla Wilson (9/15/2008)
Jeff, thanks for that great test script. I like your code for building 1,000,000 row table. I'm saving this code for reference.

Thanks for pointing out how much more efficient LEFT is than LIKE or CHARINDEX. (I knew that, but wasn't thinking about it.)
My original WHERE clause:
WHERE Address LIKE 'XX%' would be much faster as
WHERE LEFT(Address,2) = 'XX'

It's easy to get caught up in
WHERE Col1 LIKE '%aa%'
OR Col1 LIKE '%bb%
OR Col1 LIKE 'xx%'

Maybe this is where LIKE gets the bad rap - when the code should be using LEFT() instead.


Yep... from what I can see, LIKE %aa% is faster than either %aa or aa% and LEFT/RIGHT blows that away.

Thanks for the feedback on the test table. If you have any questions on how it works, please don't hesitate to ask.


--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 #569595
Posted Tuesday, September 16, 2008 6:05 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, June 10, 2013 11:21 AM
Points: 36, Visits: 124
vibhasjog ,
Please check if you are using transaction in this step in case you don't have your linked server configured for this.


Post #570122
Posted Tuesday, September 16, 2008 10:01 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, August 10, 2012 6:08 PM
Points: 1,156, Visits: 801
Jeff, great examples and test building. It amazes me you have the time to post such significant and applicable content and in such detail.

Thank you for your many contributions!
Post #570407
« Prev Topic | Next Topic »

Add to briefcase «««23456»»»

Permissions Expand / Collapse