Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hashset equivalent in SQL Server

I want to create a large table (about 45 billion rows) that is always accessed by a unique key.

Outside of the DB, the best structure to hold this is a Dictionary or a HashSet, but of course due to the size of data, it's not possible to do this outside of the database.

Does SQL Server provide a structure that's optimized for key-value access? I understand that a clustered key is very fast, but still it's an index and therefore there will be some additional disk reads associated with traversing index pages. What I would like to get from SQL Server is a "native" structure that stores data as key-value pairs and then makes it possible to access values based on keys.

In other words, my question is how to store in SQL Server 45 billion rows and efficiently access them WITHOUT having an index, clustered or non-clustered, because reading the index non-leaf pages may result in substantial IO, and since each value can be accessed by a unique key, it should be possible to have a structure where the hash of a key resolves into a physical location of the value. To get 1 value, we would need to do 1 read (unless there are hash collisions).

(an equivalent in Oracle is Hash Cluster)

Thanks for your help.

like image 969
user1044169 Avatar asked Apr 04 '12 18:04

user1044169


People also ask

What is HashSet in C?

Last Updated : 27 Mar, 2019 In C#, HashSet is an unordered collection of unique elements. This collection is introduced in.NET 3.5. It supports the implementation of sets and uses the hash table for storage.

What is the use of emptyhashset in Java?

HashSet (): It is used to create an instance of the HashSet class that is empty and uses the default equality comparer for the set type.

What is the capacity of HashSet?

The capacity of a HashSet is the number of elements it can hold. A HashSet is a dynamic collection means the size of the HashSet is automatically increased when the new elements are added. In HashSet, you can only store the same type of elements. How to create a HashSet?

What is the difference between HashSet and list in Java?

The performance of the HashSet is much better in comparison to the list. The HashSet class implements the ICollection, IEnumerable, IReadOnlyCollection, ISet, IEnumerable, IDeserializationCallback, and ISerializable interfaces. In HashSet, the order of the element is not defined. You cannot sort the elements of HashSet.


1 Answers

No such thing in SQL server. Your only option is an index. If you're going to be requesting all columns for a given key, you should use a clustered index. If you're only going to be requesting a subset, you should use a non-clustered index including only the columns you want like this:

  create index IX_MyBigTable on MyBigTable(keyColumn) include (col1, col2, col3youneed);

This will be pretty efficient.

like image 117
John Gibb Avatar answered Sep 22 '22 21:09

John Gibb