\nLast month I wrote a post called <\/font>Hash Partitioning with SQL Server 2012’s SEQUENCE object and CYCLE argument<\/a><\/font> and I was asked a good question by Eric Humphrey (t<\/u><\/font>witter<\/a><\/font>) about whether there was any advantage of using a sequence object for hash partitioning over an identity\/modulus\/computed-column technique.<\/font> <\/font><\/span><\/font>\n<\/p>\n \nAt that point I hadn’t compared the two techniques, but I wanted to perform a test eventually, so here is what I found… <\/span>This was a quick-and-dirty test, by the way, as I really should have been working on something else (first), but I needed a little “fun” time.<\/font><\/font>\n<\/p>\n \nBefore testing, I made a <\/font>few minor modifications to the schema<\/a><\/font><\/font> used in my original post:<\/font><\/font>\n<\/p>\n \n1.<\/font><\/font> <\/font><\/font><\/span><\/span><\/span>I split the range of the partition function as follows:<\/font><\/font>\n<\/p>\n \n \n<\/p>\n \n<\/font><\/font>\n<\/p>\n \nALTER PARTITION FUNCTION pfFactInternetSales () SPLIT RANGE (0)<\/font><\/font>\n<\/p>\n \n \n<\/p>\n \n<\/font><\/font>\n<\/p>\n \n2.<\/font><\/font> <\/font><\/font><\/span><\/span><\/span>I changed the sequence object to be zero-based instead of one-based:<\/font><\/font>\n<\/p>\n \n \n<\/p>\n \n<\/font><\/font>\n<\/p>\n \nCREATE SEQUENCE dbo.Seq_FactInternetSales <\/font><\/font>\n<\/p>\n \n <\/font><\/span>AS int <\/font><\/font>\n<\/p>\n \n <\/font><\/span>START WITH 0 <\/font><\/font>\n<\/p>\n \n <\/font><\/span>INCREMENT BY 1 <\/font><\/font>\n<\/p>\n \n <\/font><\/span>MINVALUE 0 <\/font><\/font>\n<\/p>\n \n <\/font><\/span>MAXVALUE 10 <\/font><\/font>\n<\/p>\n \n <\/font><\/span>CYCLE <\/font><\/font>\n<\/p>\n \n <\/font><\/span>CACHE 10;<\/font><\/font>\n<\/p>\n \nThat is all that was changed with the sequence object technique I used before. <\/font><\/font>As for a modulus technique, I created two additional columns to another version of the FactInternetSales table:<\/font><\/font>\n<\/p>\n \nProductID int NOT NULL IDENTITY(1,1),<\/font><\/font>\n<\/p>\n \n <\/font><\/span>PartitionBucketKey AS ProductID %11 <\/span>PERSISTED,<\/font><\/font>\n<\/p>\n \n \n<\/p>\n \n<\/font><\/font>\n<\/p>\n \nAfter adding the columns I referenced the PartitionBucketKey table as the partition key for the clustered index and imported the data from an INSERT…SELECT (as I did with the sequence object method).<\/font><\/font>\n<\/p>\n \n \n<\/p>\n \n<\/font><\/font>\n<\/p>\n \nSo did the performance differ between the two techniques?<\/font><\/font>\n<\/p>\n \n \n<\/p>\n \n<\/font><\/font>\n<\/p>\n \nHere are the results of eight separate tests (each executed with a cold data cache for the SELECT, truncated destination table and pre-sized data and log files<\/em>):<\/font><\/font>\n<\/p>\n \n \n<\/p>\n \n<\/font><\/font>\n<\/p>\n \n\t\t\tTest number<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tRows loaded<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tBuckets<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tHash Partition<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tMethod<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n<\/tr>\n \n\t\t\t1<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t1,207,960 rows<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t11 buckets<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t26 seconds<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tSequence<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n<\/tr>\n \n\t\t\t2<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t1,207,960 rows<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t11 buckets<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t26 seconds<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tSequence<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n<\/tr>\n \n\t\t\t3<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t1,207,960 rows<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t11 buckets<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t29 seconds<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tSequence<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n<\/tr>\n \n\t\t\t4<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t1,207,960 rows<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t11 buckets<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t26 seconds<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tSequence<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n<\/tr>\n \n\t\t\t5<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t1,207,960 rows<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t11 buckets<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t27 seconds<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tModulus<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n<\/tr>\n \n\t\t\t6<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t1,207,960 rows<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t11 buckets<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t24 seconds<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tModulus<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n<\/tr>\n \n\t\t\t7<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t1,207,960 rows<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t11 buckets<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t25 seconds<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tModulus<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n<\/tr>\n \n\t\t\t8<\/font><\/font><\/span><\/strong>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t1,207,960 rows<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t11 buckets<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\t26 seconds<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n \n\t\t\tModulus<\/font><\/font>\n\t\t\t<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \n<\/font><\/font>\n<\/p>\n \nSo the modulus method seems to perform ever-so-slightly faster than the sequence method. <\/span>Stylistically, the sequence method involved a more direct way to create X number of hash buckets (basically no calculation necessary). <\/span>With that said, the execution plans are nearly identical.<\/font><\/font>\n<\/p>\n \nSequence Plan (estimated cost – 17.4357)<\/font><\/font><\/strong>\n<\/p>\n\n\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n