Creating a virtually-hashed table

To create a virtually-hashed table, specify the maximum value for the hash region. This is the partial syntax for create table; the new parameters are shown in bold:

create table [database.[owner].]table_name 
. . .
             | {unique | primary key}
             using clustered
             (column_name [asc | desc] [{, column_name [asc | desc]}...])=
             (hash_factor [{, hash_factor}...])
                            with max num_hash_values key

Where:

NoteVirtually-hashed tables have these restrictions:

Determining values for hash_factor

You can keep the hash factor for the first key as 1. The hash factor for all the remaining key columns is greater than the maximum value of the previous key allowed in the hash region multiplied by its hash factor.

Adaptive Server allows tables with hash factors greater than 1 for the first key column to have fewer rows on a page. For example, if a table has a hash factor of 5 for the first key column, after every row in a page, space for the next four rows is kept empty. To support this, Adaptive Server requires five times the amount of table space.

If the value of a key column is greater than or equal to the hash factor of the next key column, the current row is inserted in the overflow clustered region to avoid collisions in the hash region.

For example, t is a virtually-hashed table with key columns id and age, and corresponding hash factors of (10,1). Because the hash value for rows (5, 5) and (2, 35) is 55, this may result in a hash collision.

However, because the value 35 is greater than or equal to 10 (the hash factor for the next key column, id), Adaptive Server stores the second row in the overflow clustered region, avoiding collisions in the hash region.

In another example, if u is a virtually-hashed table with a primary index and hash factors of (id1, id2, id3) = (125, 25, 5) and a max hash_value of 200:

Examples

This example creates a virtually-hashed table named orders on the pubs2 database on the order_seg segment:

create table orders(
id int,
age int,
primary key using clustered (id,age) = (10,1) with max 1000 key)
on order_seg

The layout for the data is:

This example creates a virtually-hashed table named orders on the pubs2 database on the order_seg segment:

create table orders(
id int default NULL,
age int,
primary key using clustered (id,age) = (10,1) with max 100 key,
name varchar(30)
)
on order_seg

The layout for the data is: