|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 9:37 AM
Points: 285,
Visits: 1,378
|
|
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/
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 11:21 AM
Points: 2,163,
Visits: 2,148
|
|
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.)
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 1:03 AM
Points: 10,990,
Visits: 10,543
|
|
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
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 1:03 AM
Points: 10,990,
Visits: 10,543
|
|
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
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Wednesday, May 22, 2013 8:15 PM
Points: 1,409,
Visits: 4,509
|
|
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 anywhereHello 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]
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 9:33 AM
Points: 49,
Visits: 236
|
|
| Nice article Solomon, BTW. :)
|
|
|
|
|
SSCoach
         
Group: General Forum Members
Last Login: Yesterday @ 10:25 AM
Points: 18,754,
Visits: 12,337
|
|
|
|
|
|
Forum 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 ?
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Tuesday, January 08, 2013 5:51 AM
Points: 145,
Visits: 140
|
|
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..
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Monday, December 17, 2012 10:00 AM
Points: 85,
Visits: 150
|
|
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.
|
|
|
|