Choosing the right data type for the distribution key is critical for data balance in a gbase database cluster. This guide lists the supported data types for the DISTRIBUTED BY HASH clause and flags the types that will cause errors.
Test Versions
- 8.6.2.43‑R35.5
- 9.5.3.28.18
Integer Types
INT and BIGINT are the recommended integer types for hash distribution. While SMALLINT does not throw a syntax error, its low cardinality makes it a poor choice for production workloads.
-- INT type
gbase> CREATE TABLE td_int(id INT, name VARCHAR(100)) DISTRIBUTED BY('id');
Query OK, 0 rows affected
-- BIGINT type
gbase> CREATE TABLE td_bigint(id BIGINT, name VARCHAR(100)) DISTRIBUTED BY('id');
Query OK, 0 rows affected
Character Types
Only VARCHAR is allowed as a hash distribution key. Attempting to use CHAR or TEXT will result in an immediate error.
-- CHAR type is rejected
gbase> CREATE TABLE td_char(id TINYINT, name CHAR(100)) DISTRIBUTED BY('name');
ERROR 1721 (HY000): Type of distributed column 'name' is incorrect.
-- TEXT type is also rejected
gbase> CREATE TABLE td_text(id TINYINT, name TEXT) DISTRIBUTED BY('name');
ERROR 1721 (HY000): Type of distributed column 'name' is incorrect.
-- VARCHAR type works correctly
gbase> CREATE TABLE td_varchar(id TINYINT, name VARCHAR(100)) DISTRIBUTED BY('name');
Query OK, 0 rows affected
Decimal Type
DECIMAL columns are fully supported as hash distribution keys, which is useful when you need to distribute data based on exact numeric values.
gbase> CREATE TABLE td_decimal(id DECIMAL(18,3), name TEXT) DISTRIBUTED BY('id');
Query OK, 0 rows affected
Summary
When designing a hash‑distributed table in a gbase database, stick to INT, BIGINT, VARCHAR, or DECIMAL for the distribution key. Avoid low‑cardinality types like SMALLINT and TINYINT, and never use CHAR or TEXT — they will cause the DDL to fail. Picking the right type from the start keeps your data balanced and your queries fast.
Top comments (0)