Other Schema Concepts
On this page
Reference Database
When a user creates a database, two transaction logs are created for each partition of that database, in addition one special transaction log is created called the reference database.
Reference Tables
Reference tables are relatively small tables that do not need to be distributed and are present on every node in the cluster.
Data Definition Language (DDL) commands for reference tables can be run from the child, or master aggregator.
SingleStore aggregators can take advantage of reference tables’ ubiquity by pushing joins between reference tables and a distributed table onto the leaves.clicks
table storing billions of records and a smaller customers
table with just a few million records.customers
table is small, it can be replicated on every node in the cluster.clicks
table and the customers
table, then the bulk of the work for the join will occur on the leaves.
Important
Reference tables are a convenient way to implement dimension tables.
Temporary Tables
Temporary tables can be created as Columnstore or Rowstore tables.
SingleStore does not write logs or take snapshots of temporary tables.
"Temporary table <table> is missing on leaf <host> due to failover. The table will need to be dropped and recreated."
Important
To prevent loss of data on node failover, use SingleStore tables that have high availability enabled.
Views cannot reference temporary tables because temporary tables only exist for the duration of a client session.
CREATE TEMPORARY TABLE
can be run on any aggregator, not just the master aggregator.permanent
table, including distributed joins.
Global Temporary Tables
Another type of temporary table is the global temporary table.
Note
Global temporary tables are not supported for columnstore.
Unlike temporary tables, global temporary tables are shared across sessions, i.
Global temporary tables can be used as a temporary space for processing data that can be accessed from multiple connections, for example, performing ETL (Extract, Transform, and Load) operations on modern dynamic databases.
If failover occurs, global temporary tables lose data and enter an errored state; they need to be dropped and recreated.
DDL such as CREATE ROWSTORE GLOBAL TEMPORARY TABLE
and DML for global temporary tables can be run on a master, or a child aggregator node.
Note: Both global temporary tables and non-global temporary tables cannot be altered.
Types of Indexes
SingleStore, like all standard SQL databases, allows the creation of indexes on tables, which speed up certain access patterns.
Note
KEY() USING CLUSTERED COLUMNSTORE
is a legacy syntax that is equivalent to SORT KEY()
.SORT KEY()
.
Skiplist Indexes
The default index type in SingleStore is a skiplist.
Unlike B-Trees in MySQL, skiplists in SingleStore are uni-directional (singly linked).ASC
) or descending (DESC
).ASC
.ASC
index and you run a query that would traverse the index in descending order (ORDER BY DESC
for example), then the query will require a more expensive iteration than if the index were DESC
.
SingleStore supports skiplists only on rowstore tables.
Columnstore Indexes
Columnstore indexes leverage columnstore technology to efficiently store and retrieve large numbers of values from disk (using flash or SSD is recommended).
Hash Indexes
Due to the restrictive case detailed above, HASH
indexes should only be used when there is a demonstrated need and measurable benefit on your particular dataset and workload.HASH
indexes provide fast exact-match access to unique values.hash(column_
.HASH
indexes on both columnstore and rowstore tables.
Warning
For rowstore tables, a HASH
index will only be utilized if the query filters on all the columns in a multi-column HASH
index.
A columnstore table cannot have a multi-column HASH
index.
Consider an example table:
CREATE TABLE t(a int, b int, INDEX(a, b) USING HASH);
Suppose we are running queries like:
SELECT * FROM t WHERE a < 3;
EXPLAIN
shows us that since we are performing a range scan and not filtering on all the columns in our hash index, a full Table Scan is performed.
EXPLAIN SELECT * FROM t WHERE a < 3;
+------------------------------------------------+
| EXPLAIN |
+------------------------------------------------+
| Gather partitions:all |
| Project [t.a, t.b] |
| Filter [t.a < 3] |
| TableScan db.t |
+------------------------------------------------+
The hash index is only utilized if the query uses only equality predicates, and filters on all columns in the hash index.
EXPLAIN SELECT * FROM t WHERE a=3 AND b=7;
+--------------------------------------------------------------------------------------------------------------------------+
| EXPLAIN |
+--------------------------------------------------------------------------------------------------------------------------+
| Gather partitions:all |
| Project [t.a, t.b] |
| IndexRangeScan db.t, KEY a (a, b) USING HASH storage:lf_hashtable scan:[a = 3 AND b = 7] |
+--------------------------------------------------------------------------------------------------------------------------+
Important
A query on a columnstore table that employs an equality filter on a column that has a hash index defined on that column will always use the hash index.
Runtime Plan Choosing
SingleStore can dynamically select which index to use for a query at runtime.
Index Hints
SingleStore supports the following index hint syntax:
tbl_name [index_hint]index_hint:USE {INDEX | KEY} (index_list)| IGNORE {INDEX | KEY} (index_list)| FORCE {INDEX | KEY} (index_list)index_list:index_name [, index_name] ...
For example:
SELECT * FROM t1 USE INDEX(idx_name);
--OR
SELECT * FROM t1 FORCE INDEX(idx_name);
-
USE
andFORCE
hints force the use of one of the specified indexes to run the query.In SingleStore, there is no difference between a USE
andFORCE
hint. -
IGNORE
hints disallow the specified indexes from being used to run the query.
The EXPLAIN <query>
statement can be used to show which indexes the query considers and which one it will actually use.
Index Commands
Related Commands
An index may also be specified when creating or altering tables.
Related Topics
-
Training: SingleStore Indexes
Last modified: September 13, 2024