Search…
Tables
DDL - Tables
These functions are used to create and modify data tables in OmniSci.

Nomenclature Constraints

Table names must use the NAME format, described in regex notation as:
1
[A-Za-z_][A-Za-z0-9\$_]*
Copied!
Table and column names can include quotes, spaces, and the underscore character. Other special characters are permitted if the name of the table or column is enclosed in double quotes (" ").
    Spaces and special characters other than underscore (_) cannot be used in OmniSci Immerse.
    Column and table names enclosed in double quotes cannot be used in OmniSci Immerse

CREATE TABLE

1
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] <table>
2
(<column> <type> [NOT NULL] [DEFAULT <value>] [ENCODING <encodingSpec>],
3
[SHARD KEY (<column>)],
4
[SHARED DICTIONARY (<column>) REFERENCES <table>(<column>)], ...)
5
[WITH (<property> = value, ...)];
Copied!
Create a table named <table> specifying <columns> and table properties.

Supported Datatypes

Datatype
Size (bytes)
Notes
BIGINT
8
Minimum value: -9,223,372,036,854,775,807; maximum value: 9,223,372,036,854,775,807.
BOOLEAN
1
TRUE: 'true', '1', 't'. FALSE: 'false', '0', 'f'. Text values are not case-sensitive.
DATE*
4
Same as DATE ENCODING DAYS(32).
DATE ENCODING DAYS(32)
4
Range in years: +/-5,883,517 around epoch. Maximum date January 1, 5885487 (approximately). Minimum value: -2,147,483,648; maximum value: 2,147,483,647. Supported formats when using COPY FROM: mm/dd/yyyy, dd-mmm-yy, yyyy-mm-dd, dd/mmm/yyyy.
DATE ENCODING DAYS(16)
2
Range in days: -32,768 - 32,767 Range in years: +/-90 around epoch, April 14, 1880 - September 9, 2059. Minumum value: -2,831,155,200; maximum value: 2,831,068,800. Supported formats when using COPY FROM: mm/dd/yyyy, dd-mmm-yy, yyyy-mm-dd, dd/mmm/yyyy.
DATE ENCODING FIXED(32)
4
In DDL statements defaults to DATE ENCODING DAYS(16). Deprecated.
DATE ENCODING FIXED(16)
2
In DDL statements defaults to DATE ENCODING DAYS(16). Deprecated.
DECIMAL
2, 4, or 8
Takes precision and scale parameters: DECIMAL(precision,scale).
Size depends on precision:
    Up to 4: 2 bytes
    5 to 9: 4 bytes
    10 to 18 (maximum): 8 bytes
Scale must be less than precision.
DOUBLE
8
Variable precision. Minimum value: -1.79 x e^308; maximum value: 1.79 x e^308.
FLOAT
4
Variable precision. Minimum value: -3.4 x e^38; maximum value: 3.4 x e^38.
INTEGER
4
Minimum value: -2,147,483,647; maximum value: 2,147,483,647.
SMALLINT
2
Minimum value: -32,767; maximum value: 32,767.
TEXT ENCODING DICT
4
Max cardinality 2 billion distinct string values
TEXT ENCODING NONE
Variable
Size of the string + 6 bytes
TIME
8
Minimum value: 00:00:00; maximum value: 23:59:59.
TIMESTAMP
8
Linux timestamp from -30610224000 (1/1/1000 00:00:00.000) through 29379542399 (12/31/2900 23:59:59.999).
Can also be inserted and stored in human-readable format:
    YYYY-MM-DD HH:MM:SS
    YYYY-MM-DDTHH:MM:SS (The T is dropped when the field is populated.)
TINYINT
1
Minimum value: -127; maximum value: 127.
* In OmniSci release 4.4.0 and higher, you can use existing 8-byte DATE columns, but you can create only 4-byte DATE columns (default) and 2-byte DATE columns (see DATE ENCODING FIXED(16)).
For more information, see Datatypes and Fixed Encoding.
For geospatial datatypes, see Geospatial Primitives.

Examples

Create a table named tweets and specify the columns, including type, in the table.
1
CREATE TABLE IF NOT EXISTS tweets (
2
tweet_id BIGINT NOT NULL,
3
tweet_time TIMESTAMP NOT NULL ENCODING FIXED(32),
4
lat FLOAT,
5
lon FLOAT,
6
sender_id BIGINT NOT NULL,
7
sender_name TEXT NOT NULL ENCODING DICT,
8
location TEXT ENCODING DICT,
9
source TEXT ENCODING DICT,
10
reply_to_user_id BIGINT,
11
reply_to_tweet_id BIGINT,
12
lang TEXT ENCODING DICT,
13
followers INT,
14
followees INT,
15
tweet_count INT,
16
join_time TIMESTAMP ENCODING FIXED(32),
17
tweet_text TEXT,
18
state TEXT ENCODING DICT,
19
county TEXT ENCODING DICT,
20
place_name TEXT,
21
state_abbr TEXT ENCODING DICT,
22
county_state TEXT ENCODING DICT,
23
origin TEXT ENCODING DICT,
24
phone_numbers bigint);
Copied!
Create a table named delta and assign a default value San Francisco to column city.
1
CREATE TABLE delta (
2
id INTEGER NOT NULL,
3
name TEXT NOT NULL,
4
city TEXT NOT NULL DEFAULT 'San Francisco' ENCODING DICT(16));
Copied!
Default values currently have the following limitations:
    Only literals can be used for column DEFAULT values; expressions are not supported.
    You cannot define a DEFAULT value for a shard key. For example, the following does not parse: CREATE TABLE tbl (id INTEGER NOT NULL DEFAULT 0, name TEXT, shard key (id)) with (shard_count = 2);
    For arrays, use the following syntax: ARRAY[A, B, C, …. N]
    The syntax {A, B, C, ... N} is not supported.
    Some literals, like NUMERIC and GEO types, are not checked at parse time. As a result, you can define and create a table with malformed literal as a default value, but when you try to insert a row with a default value, it will throw an error.

Supported Encoding

Encoding
Descriptions
DICT
Dictionary encoding on string columns (default for TEXT columns). Limit of 2 billion unique string values.
FIXED (bits)
Fixed length encoding of integer or timestamp columns. See Datatypes and Fixed Encoding.
NONE
No encoding. Valid only on TEXT columns. No Dictionary is created. Aggregate operations are not possible on this column type.

WITH Clause Properties

Property
Description
fragment_size
Number of rows per fragment that is a unit of the table for query processing. Default: 32 million rows, which is not expected to be changed.
max_rollback_epochs
Limit the number of epochs a table can be rolled back to. Limiting the number of epochs helps to limit the amount of on-disk data and prevent unmanaged data growth.
Limiting the number of rollback epochs also can increase system startup speed, especially for systems on which data is added in small batches or singleton inserts. Default: 3.
The following example creates the table test_table and sets the maximum epoch rollback number to 50:
CREATE TABLE test_table(a int) WITH (MAX_ROLLBACK_EPOCHS = 50);
max_rows
Used primarily for streaming datasets to limit the number of rows in a table, to avoid running out of memory or impeding performance. When the max_rows limit is reached, the oldest fragment is removed. When populating a table from a file, make sure that your row count is below the max_rows setting. If you attempt load more rows at one time than the max_rows setting defines, the records up to the max_rows limit are removed, leaving only the additional rows. Default: 2^62. In a distributed system, the maximum number of rows is calculated as max_rows * leaf_count. In a sharded distributed system, the maximum number of rows is calculated as max_rows * shard_count.
page_size
Number of I/O page bytes. Default: 1MB, which does not need to be changed.
partitions
Partition strategy option:
    SHARDED: Partition table using sharding.
    REPLICATED: Partition table using replication.
shard_count
Number of shards to create, typically equal to the number of GPUs across which the data table is distributed.
sort_column
Name of the column on which to sort during bulk import.

Sharding

Sharding partitions a database table across multiple servers so each server has a part of the table with the same columns but with different rows. Partitioning is based on a sharding key defined when you create the table.
Without sharding, the dimension tables involved in a join are replicated and sent to each GPU, which is not feasible for dimension tables with many rows. Specifying a shard key makes it possible for the query to execute efficiently on large dimension tables.
Currently, specifying a shard key is useful for joins, only:
    If two tables specify a shard key with the same type and the same number of shards, a join on that key only sends a part of the dimension table column data to each GPU.
    For multi-node installs, the dimension table does not need to be replicated and the join executes locally on each leaf.

Constraints

    A shard key must specify a single column to shard on. There is no support for sharding by a combination of keys.
    One shard key can be specified for a table.
    Data are partitioned according to the shard key and the number of shards (shard_count).
    A value in the column specified as a shard key is always sent to the same partition.
    The number of shards should be equal to the number of GPUs in the cluster.
    Sharding is allowed on the following column types:
      DATE
      INT
      TEXT ENCODING DICT
      TIME
      TIMESTAMP
    Tables must share the dictionary for the column to be involved in sharded joins. If the dictionary is not specified as shared, the join does not take advantage of sharding. Dictionaries are reference-counted and only dropped when the last reference drops.

Recommendations

    Set shard_count to the number of GPUs you eventually want to distribute the data table across.
    Referenced tables must also be shard_count -aligned.
    Sharding should be minimized because it can introduce load skew accross resources, compared to when sharding is not used.
Examples
Basic sharding:
1
CREATE TABLE customers(
2
accountId text,
3
name text,
4
SHARD KEY (accountId))
5
WITH (shard_count = 4);
Copied!
Sharding with shared dictionary:
1
CREATE TABLE transactions(
2
accountId text,
3
action text,
4
SHARD KEY (accountId),
5
SHARED DICTIONARY (accountId) REFERENCES customers(accountId))
6
WITH (shard_count = 4);
Copied!

Temporary Tables

Using the TEMPORARY argument creates a table that persists only while the server is live. They are useful for storing intermediate result sets that you access more than once.
Adding or dropping a column from a temporary table is not supported.

Example

1
CREATE TEMPORARY TABLE customers(
2
accountId TEXT,
3
name TEXT,
4
timeCreated TIMESTAMP)
Copied!

CREATE TABLE AS SELECT

1
CREATE TABLE [IF NOT EXISTS] <newTableName> AS (<SELECT statement>) [WITH (<property> = value, ...)];
Copied!
Create a table with the specified columns, copying any data that meet SELECT statement criteria.

WITH Clause Properties

Property
Description
fragment_size
Number of rows per fragment that is a unit of the table for query processing. Default = 32 million rows, which is not expected to be changed.
max_chunk_size
Size of chunk that is a unit of the table for query processing. Default: 1073741824 bytes (1 GB), which is not expected to be changed.
max_rows
Used primarily for streaming datasets to limit the number of rows in a table. When the max_rows limit is reached, the oldest fragment is removed. When populating a table from a file, make sure that your row count is below the max_rows setting. If you attempt load more rows at one time than the max_rows setting defines, the records up to the max_rows limit are removed, leaving only the additional rows. Default = 2^62.
page_size
Number of I/O page bytes. Default = 1MB, which does not need to be changed.
partitions
Partition strategy option:
    SHARDED: Partition table using sharding.
    REPLICATED: Partition table using replication.
use_shared_dictionaries
Controls whether the created table creates its own dictionaries for text columns, or instead shares the dictionaries of its source table. Uses shared dictionaries by default (true), which increases the speed of table creation.
Setting to false shrinks the dictionaries if SELECT for the created table has a narrow filter; for example: CREATE TABLE new_table AS SELECT * FROM old_table WITH (USE_SHARED_DICTIONARIES='false');
vacuum
Formats the table to more efficiently handle DELETE requests. The only parameter available is delayed. Rather than immediately remove deleted rows, vacuum marks items to be deleted, and they are removed at an optimal time.

Examples

Create the table newTable. Populate the table with all information from the table oldTable, effectively creating a duplicate of the original table.
1
CREATE TABLE newTable AS (SELECT * FROM oldTable);
Copied!
Create a table named trousers. Populate it with data from the columns name, waist, and inseam from the table wardrobe.
1
CREATE TABLE trousers AS (SELECT name, waist, inseam FROM wardrobe);
Copied!
Create a table named cosmos. Populate it with data from the columns star and planet from the table universe where planet has the class M.
1
CREATE TABLE IF NOT EXISTS cosmos AS (SELECT star, planet FROM universe WHERE class='M');
Copied!

ALTER TABLE

1
ALTER TABLE <table> RENAME TO <table>;
2
ALTER TABLE <table> RENAME COLUMN <column> TO <column>;
3
ALTER TABLE <table> ADD [COLUMN] <column> <type> [NOT NULL] [ENCODING <encodingSpec>];
4
ALTER TABLE <table> ADD (<column> <type> [NOT NULL] [ENCODING <encodingSpec>], ...);
5
ALTER TABLE <table> ADD (<column> <type> DEFAULT <value>);
6
ALTER TABLE <table> DROP COLUMN <column_1>[, <column_2>, ...];
7
ALTER TABLE <table> SET MAX_ROLLBACK_EPOCHS=<value>
Copied!

Examples

Rename the table tweets to retweets.
1
ALTER TABLE tweets RENAME TO retweets;
Copied!
Rename the column source to device in the table retweets.
1
ALTER TABLE retweets RENAME COLUMN source TO device;
Copied!
Add the column pt_dropoff to table tweets with a default value point(0,0).
1
ALTER TABLE tweets ADD COLUMN pt_dropoff POINT DEFAULT 'point(0 0)';
Copied!
Add multiple columns a, b, and c to table table_one with a default value of 15 for column b.
1
ALTER TABLE table_one ADD a INTEGER, b INTEGER NOT NULL DEFAULT 15, c TEXT;
Copied!
Default values currently have the following limitations:
    Only literals can be used for column DEFAULT values; expressions are not supported.
    For arrays, use the following syntax: ARRAY[A, B, C, …. N]. The syntax {A, B, C, ... N} is not supported.
    Some literals, like NUMERIC and GEO types, are not checked at parse time. As a result, you can define and create a table with a malformed literal as a default value, but when you try to insert a row with a default value, it throws an error.
Add the column lang to the table tweets using a TEXT ENCODING DICTIONARY.
1
ALTER TABLE tweets ADD COLUMN lang TEXT ENCODING DICT;
Copied!
Add the columns lang and encode to the table tweets using a TEXT ENCODING DICTIONARY for each.
1
ALTER TABLE tweets ADD (lang TEXT ENCODING DICT, encode TEXT ENCODING DICT);
Copied!
Drop the column pt_dropoff from table tweets.
1
ALTER TABLE tweets DROP COLUMN pt_dropoff;
Copied!
Limit on-disk data growth by setting the number of allowed epoch rollbacks to 50:
1
ALTER TABLE test_table SET MAX_ROLLBACK_EPOCHS=50;
Copied!
    You cannot add a dictionary-encoded string column with a shared dictionary when using ALTER TABLE ADD COLUMN.
    Currently, OmniSci does not support adding a geo column type (POINT, LINESTRING, POLYGON, or MULTIPOLYGON) to a table.
    OmniSci supports ALTER TABLE RENAME TABLE and ALTER TABLE RENAME COLUMN for temporary tables. OmniSci does not support ALTER TABLE ADD COLUMN to modify a temporary table.

DROP TABLE

1
DROP TABLE [IF EXISTS] <table>;
Copied!
Deletes the table structure, all data from the table, and any dictionary content unless it is a shared dictionary. (See the Note regarding disk space reclamation.)

Example

1
DROP TABLE IF EXISTS tweets;
Copied!

DUMP TABLE

1
DUMP TABLE <table> TO '<filepath>' [WITH (COMPRESSION='<compression_program>')];
Copied!
Archives data and dictionary files of the table <table> to file <filepath>.
Valid values for <compression_program> include:
    gzip (default)
    pigz
    lz4
    none
If you do not choose a compression option, the system uses gzip if it is available. If gzip is not installed, the file is not compressed.
The file path must be enclosed in single quotes.
    Dumping a table locks writes to that table. Concurrent reads are supported, but you cannot import to a table that is being dumped.
    The DUMP command is not supported on distributed configurations.
    You must have a least GRANT CREATE ON DATABASE privilege level to use the DUMP command.

Example

1
DUMP TABLE tweets TO '/opt/archive/tweetsBackup.gz' WITH (COMPRESSION='gzip');
Copied!

RENAME TABLE

1
RENAME TABLE <table> TO <table>[, <table> TO <table>, <table> TO <table>...];
Copied!
Rename a table or multiple tables at once.

Examples

Rename a single table:
1
RENAME TABLE table_A TO table_B;
Copied!
Swap table names:
1
RENAME TABLE table_A TO table_B, table_B TO table_A;
2
3
RENAME TABLE table_A TO table_B, table_B TO table_C, table_C TO table_A;
Copied!
Swap table names multiple times:
1
RENAME TABLE table_A TO table_A_stale, table_B TO table_B_stale, table_A_new TO table_A, table_B_new TO table_B;
Copied!

RESTORE TABLE

1
RESTORE TABLE <table> FROM '<filepath>' [WITH (COMPRESSION='<compression_program>'];
Copied!
Restores data and dictionary files of table <table> from the file at <filepath>. If you specified a compression program when you used the DUMP TABLE command, you must specify the same compression method during RESTORE.
Restoring a table decompresses and then reimports the table. You must have enough disk space for both the new table and the archived table, as well as enough scratch space to decompress the archive and reimport it.
The file path must be enclosed in single quotes.
    Restoring a table locks writes to that table. Concurrent reads are supported, but you cannot import to a table that is being restored.
    The RESTORE command is not supported on distributed configurations.
    You must have a least GRANT CREATE ON DATABASE privilege level to use the RESTORE command.

Example

1
RESTORE TABLE tweets FROM '/opt/archive/tweetsBackup.gz' WITH (COMPRESSION='gzip');
Copied!

TRUNCATE TABLE

1
TRUNCATE TABLE <table>;
Copied!
Use the TRUNCATE TABLE statement to remove all rows from a table without deleting the table structure.
This releases table on-disk and memory storage and removes dictionary content unless it is a shared dictionary. (See the note regarding disk space reclamation.)
Removing rows is more efficient than using DROP TABLE. Dropping followed by recreating the table invalidates dependent objects of the table requiring you to regrant object privileges. Truncating has none of these effects.

Example

1
TRUNCATE TABLE tweets;
Copied!
When you DROP or TRUNCATE, the command returns almost immediately. The directories to be purged are marked with the suffix \_DELETE_ME_. The files are automatically removed asynchronously.
In practical terms, this means that you will not see a reduction in disk usage until the automatic task runs, which might not start for up to five minutes.
You might also see directory names appended with \_DELETE_ME_. You can ignore these, with the expectation that they will be deleted automatically over time.

OPTIMIZE TABLE

1
OPTIMIZE TABLE [<table>] [WITH (VACUUM='true')]
Copied!
Use this statement to remove rows from storage that have been marked as deleted via DELETE statements.
When run without the vacuum option, the column-level metadata is recomputed for each column in the specified table. OmniSciDB makes heavy use of metadata to optimize query plans, so optimizing table metadata can increase query performance after metadata widening operations such as updates or deletes. If the configuration parameter enable-auto-metadata-update is not set, OmniSciDB does not narrow metadata during an update or delete — metadata is only widened to cover a new range.
When run with the vacuum option, it removes any rows marked "deleted" from the data stored on disk. Vacuum is a checkpointing operation, so new copies of any vacuum records are deleted. Using OPTIMIZE with the VACUUM option compacts pages and deletes unused data files that have not been repopulated.
Beginning with OmniSci release 5.6.0, OPTIMIZE should be used infrequently, because UPDATE, DELETE, and IMPORT queries manage space more effectively.

VALIDATE

1
VALIDATE
Copied!
Performs checks for negative and inconsistent epochs across table shards for single-node configurations.
If VALIDATE detects epoch-related issues, it returns a report similar to the following:
1
omnisql> validate;
2
Result
3
4
Negative epoch value found for table "my_table". Epoch: -1.
5
Epoch values for table "my_table_2" are inconsistent:
6
Table Id Epoch
7
========= =========
8
4 1
9
5 2
Copied!
If no issues are detected, it reports as follows:
1
Instance OK
Copied!

VALIDATE CLUSTER

1
VALIDATE CLUSTER [WITH (REPAIR_TYPE = ['NONE' | 'REMOVE'])];
Copied!
Perform checks and report discovered issues on a running OmniSci cluster. Compare metadata between the aggregator and leaves to verify that the logical components between the processes are identical.
VALIDATE CLUSTER also detects and reports issues related to table epochs. It reports when epochs are negative or when table epochs across leaf nodes or shards are inconsistent.

Examples

If VALIDATE CLUSTER detects issues, it returns a report similar to the following:
1
[email protected] ~]$ /mnt/gluster/dist_mapd/mapd-sw2/bin/mapdql -p HyperInteractive
2
User admin connected to database omnisci
3
omnisql> validate cluster;
4
Result
5
Node Table Count
6
=========== ===========
7
Aggregator 1116
8
Leaf 0 1114
9
Leaf 1 1114
10
No matching table on Leaf 0 for Table cities_dtl_POINTS table id 56
11
No matching table on Leaf 1 for Table cities_dtl_POINTS table id 56
12
No matching table on Leaf 0 for Table cities_dtl table id 80
13
No matching table on Leaf 1 for Table cities_dtl table id 80
14
Table details don't match on Leaf 0 for Table view_geo table id 95
15
Table details don't match on Leaf 1 for Table view_geo table id 95
Copied!
If no issues are detected, it will report as follows:
1
Cluster OK
Copied!
You can include the WITH(REPAIR_TYPE) argument. (REPAIR_TYPE='NONE') is the same as running the command with no argument. (REPAIR_TYPE='REMOVE') removes any leaf objects that have issues. For example:
1
VALIDATE CLUSTER WITH (REPAIR_TYPE = 'REMOVE');
Copied!

Epoch Issue Example

This example output from the VALIDATE CLUSTER command on a distributed setup shows epoch-related issues:
1
omnisql> validate cluster;
2
Result
3
4
Negative epoch value found for table "my_table". Epoch: -16777216.
5
Epoch values for table "my_table_2" are inconsistent:
6
Node Table Id Epoch
7
========= ========= =========
8
Leaf 0 4 1
9
Leaf 1 4 2
Copied!
Last modified 13d ago