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

Improving Performance of Cross-Partition Queries Expand / Collapse
Author
Message
Posted Tuesday, May 04, 2010 10:07 AM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Thursday, April 17, 2014 3:01 PM
Points: 342, Visits: 1,781
UMG Developer (5/4/2010)
What happens if you use a sub query to get the minimum value for each partition, and then get the min of that?

SELECT MIN(MinIntDate)
FROM (SELECT PartitionID, MIN(IntDate) MinIntDate
FROM dbo.ExampleTablePartitioned
GROUP BY PartitionID) a



Hello. I just tried your code and it had the same effect as the regular SELECT MIN(IntDate). It took 10 - 11 seconds each time. There is really no getting around using the Partition Key in the WHERE clause (outside of doing a non-partitioned Index like Paul mentioned).

Take care,
Solomon...





SQL# - http://www.SQLsharp.com/
Post #915446
Posted Tuesday, May 04, 2010 10:16 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, March 27, 2014 8:50 AM
Points: 2,163, Visits: 2,184
Solomon Rutzky (5/4/2010)
Hello. I just tried your code and it had the same effect as the regular SELECT MIN(IntDate). It took 10 - 11 seconds each time. There is really no getting around using the Partition Key in the WHERE clause (outside of doing a non-partitioned Index like Paul mentioned).


What about the other version I edited in:

SELECT MIN(MinIntDate)  
FROM (SELECT PartitionID FROM dbo.ExampleTable GROUP BY PartitionID) a
CROSS APPLY (SELECT MIN(IntDate) MinIntDate
FROM dbo.ExampleTable b
WHERE B.PartitionID = a.PartitionID) c

I would hope it was similar to the other cross apply that Paul supplied. (I guess the real problem there is that you would have to have an index with the PartitionID as the first column to get the best performance and using Sys.Partitions avoids that.)
Post #915453
Posted Tuesday, May 04, 2010 10:26 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 5:04 PM
Points: 11,168, Visits: 10,939
UMG Developer (5/4/2010)
I would hope it was similar to the other cross apply that Paul supplied. (I guess the real problem there is that you would have to have an index with the PartitionID as the first column to get the best performance and using Sys.Partitions avoids that.)

Ah, sadly no - that APPLY results in two full scans of the partitioned index. You can use the test rig code to test for yourself - just don't create the non-partitioned index. You have to include the $PARTITION function to help the optimiser along.




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #915461
Posted Tuesday, May 04, 2010 10:38 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 5:04 PM
Points: 11,168, Visits: 10,939
Solomon Rutzky (5/4/2010)
...you make a good point about the non-partitioned index. However, it is not that applicable in my situation. The index comes with two costs: disk space (in this case over 1 GB!) and it needs to be maintained across INSERT and DELETE operations.

I guess it comes down to circumstances and personal preference.

Not looking to start a debate here, but I just want to respond briefly:

The non-partitioned index could replace the partitioned index, so no additional space or maintenance would be required. I'm not sure the space or maintenance overhead arguments are terribly strong ones.

Your precise circumstances may differ, but I think that in general, I would prefer the solution that just works every time, without having to rewrite queries, or remember to do the trick whenever new code is written containing MIN or MAX. I dislike the $PARTITION approach for similar reasons, but it does strike me as preferable to the WHILE loop + hard coded partition count.

Paul




Paul White
SQL Server MVP
SQLblog.com
@SQL_Kiwi
Post #915473
Posted Tuesday, May 04, 2010 10:46 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, April 03, 2014 12:46 PM
Points: 1,413, Visits: 4,531
Solomon Rutzky (5/4/2010)
alen teplitsky (5/4/2010)
nice article

we have a 2TB database we're going to be moving to new hardware soon ... but there is no way to test it since we don't have 2TB of empty space anywhere


Hello Alen and thanks. I am surprised that you cannot find 2 TB of available space given that I keep hearing how "disk is cheap" . Good luck!

Take care,
Solomon...


its finding 2TB of usable space after you create separate RAID1 volumes for all the partitions, logs and tempdb

$7500 or so to buy the disk and jbod for a soon to be free server
$8000 to buy a new server with just enough disk


https://plus.google.com/100125998302068852885/posts?hl=en
http://twitter.com/alent1234
x-box live gamertag: i am null
[url=http://live.xbox.com/en-US/MyXbox/Profile[/url]
Post #915475
Posted Tuesday, May 04, 2010 11:02 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Today @ 8:21 AM
Points: 49, Visits: 259
Nice article Solomon, BTW. :)
Post #915496
Posted Tuesday, May 04, 2010 2:58 PM


SSC-Insane

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

Group: General Forum Members
Last Login: Today @ 2:38 PM
Points: 20,485, Visits: 14,142
Interesting solution.

Thanks for the article.

I also like the additional points of Interest that Paul has raised. They bring a good amount of education as well.




Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #915679
Posted Wednesday, May 05, 2010 12:14 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, September 02, 2010 3:07 AM
Points: 2, Visits: 8

How about this query ?

SELECT MIN(etp.IntDate)
FROM dbo.ExampleTablePartitioned etp
WHERE etp.PartitionID in (1,2,3,4,5,6,7,8,9,10)

Will we get the performance as good as the case when we didn't have any partition ?
Post #915835
Posted Wednesday, May 05, 2010 1:41 AM
SSC-Enthusiastic

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

Group: General Forum Members
Last Login: Wednesday, March 26, 2014 8:16 AM
Points: 161, Visits: 142
Hi,

I found this article interesting, since partitioning is not a subject I have much experience with. I see that the more experienced users have found some errors/shortcomings. But for a "partitioning beginner" like me, you seem to have highlighted some interesting points.

It seems as if PartitionID is crucial when it comes to the performance of the query. One thing struck me: Using a while loop in combination with a table variable shouldn't, in general, be the best performing option.

How would this query perform:
SELECT <something>
FROM <the partitioned table>
WHERE etp.PartitionID <= 10

It might be that it's just as expensive as the other examples in your article?

..Håvard..
Post #915874
Posted Wednesday, May 05, 2010 2:20 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Thursday, December 19, 2013 10:42 AM
Points: 85, Visits: 152
Yes, this is the good old and tiring issue in Sqlserver. In oracle, partitions are just faster in all scenarios, however, this is not the case with sqlserver. It does not improve performance, but actually bring more penalties than improvements in my scenarios.

Somewhere I read that the 2008 version has some optimizations on the query side over partitions. I cannot remember where but I would say it was on the release notes. Unfortunately I am working in environments where everything is sql2005.

Has anyone tried if this is still an issue on sql2008?

Best regards,


Francisco Isla.
Post #915883
« Prev Topic | Next Topic »

Add to briefcase ««12345»»»

Permissions Expand / Collapse