SQL Server内存中OLTP哈希索引设置BUCKET_COUNT的值

在内存优化表中创建哈希索引时,我可以为变量BUCKET_COUNT设置值

CREATE TABLE [Table1] (
[Id] INT NOT NULL IDENTITY(1,1) PRIMARY KEY NONCLUSTERED HASH 
                                WITH (BUCKET_COUNT = 1000000),
[Name] NVARCHAR(100) NOT NULL
) 
WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA);

这个变量的最佳值是多少?

最佳答案 根据
Determining the Correct Bucket Count for Hash Indexes

In most cases the bucket count should be between 1 and 2 times the
number of distinct values in the index key
. If the index key contains
a lot of duplicate values, on average there are more than 10 rows for
each index key value, use a nonclustered index instead

You may not always be able to predict how many values a particular index key may have or will have. Performance should be acceptable if the BUCKET_COUNT value is within 5 times of the actual number of key values.

和:

Primary Key and Unique Indexes

Because the primary key index is unique, the number of distinct values in the key corresponds to the number of rows in the table.

点赞