Understanding Keys and Indexes in SingleStore
This page seeks to explain behaviors of and interaction between keys and indexes in SingleStore.
For basic keys, there is a one to one relationship with indexes.KEY(.
(alone), or PRIMARY KEY(.
is used in CREATE TABLE
when defining a given key, an index is created.
Key or Index |
Function |
Table Compatibility |
Notes and Limitations |
Column Compatibility |
---|---|---|---|---|
Shard key |
Responsible for distribution of data across partitions. |
A shard key (unique or non-unique) can be defined for either columnstore or rowstore tables. |
If a shard and/or primary key is not defined for a given table, that table becomes keylessly sharded. If a primary key is defined, but a shard key is not, the primary key becomes the shard key. Only one primary key per table can be created. The shard key must be a subset of the columns in the primary key, if one is defined. |
N/A |
Primary key |
A group of 1 or more columns from a table that uniquely identifies a row in the table, and serves to prevent data skew. |
A primary key can be defined for either columnstore or rowstore tables. |
The primary key must contain all columns in the shard key.
|
N/A |
Columnstore sort key |
Stores data on disk in a columnstore format. |
Columnstore sort keys may only be defined on columnstore tables. |
A columnstore sort key can be created using the
|
N/A |
Rowstore key |
Creates an index on a column or group of columns to support fast lookups, or uniqueness enforcement. |
A rowstore key may only be defined on rowstore tables. |
The index created with this key can be defined as a skiplist or hash index. |
N/A |
Skiplist index |
A skiplist is a data structure optimized for ordered data that allows for queries to quickly seek data by binary searching. |
Skiplist indexes may only be defined on rowstore tables. |
This is the default index type for rowstore tables, unless otherwise specified. |
N/A |
Hash index |
A hash table is a data structure optimized for fast equality lookups by a key. |
A hash index can be defined for either columnstore or rowstore tables. |
Only one unique hash index per table can be created, and one or multiple columns are allowed per hash index. |
Cannot be created on columns with the following dataypes: |
Full-text index |
Full-text search allows searching for words or phrases in a large body of text through an inverted index. |
Full-text indexes may only be defined on columnstore tables, during the |
N/A |
Can only be created on columns with the following data types: |
Geospatial index |
A geospatial index can be defined on columns containing spatial data and serves to speed up queries on them. |
Geospatial indexes may only be defined on rowstore tables. |
N/A |
Can only be created on columns with the following data types: |
Last modified: April 2, 2024