This topic describes the data types supported by AnalyticDB for MySQL, their differences from MySQL data types, and implicit type conversion rules.
Basic data types supported by AnalyticDB for MySQL
Category | Data type | Description | Comparison with MySQL data types |
Numeric |
| Valid values:
| No difference. |
| Valid values: | No difference. | |
| Valid values: | No difference. | |
| Valid values: | The | |
| Valid values: | No difference. | |
| Valid values: | No difference. | |
| Valid values: | No difference. | |
|
|
To adjust the maximum precision, contact Technical Support. | |
String |
| A VARCHAR value can be up to 16 MB in size. You do not need to specify the length when you use VARCHAR. Note If you specify the length, such as VARCHAR(255), the number in the parentheses is used only for syntactic compatibility. The actual length varies based on the data size (up to 16 MB) and may exceed 255 characters. Do not perform length validation by using the specified length. | The |
| The length of storage characters. | The | |
Time |
| Valid values: |
|
| Valid values: |
| |
| Valid values: Important By default, |
| |
| Valid values: Note By default, |
| |
Spatial |
| Geographic coordinates x and y. | No difference. |
Implicit type conversion
Implicit type conversion refers to the automatic type conversion performed by AnalyticDB for MySQL based on the context and type conversion rules when you execute SQL query operations.
The implicit type conversion rules of AnalyticDB for MySQL cover common basic data types. Complex data types do not support implicit type conversion.
If the default implicit type conversion rules do not meet your business requirements, you can use explicit type conversion.
Projection conversion rules
When columns in SELECT statements are compared with constants, the return types will be implicitly converted into the data types displayed in the following table. If implicit type conversion is not supported, an error occurs.
Column/Constant | VARCHAR | BOOLEAN | TINYINT | SMALLINT | INTEGER | BIGINT | DECIMAL | DOUBLE | TIME | DATE | TIMESTAMP | DATETIME |
VARCHAR | VARCHAR | BOOLEAN | BIGINT | BIGINT | BIGINT | BIGINT | DECIMAL | DOUBLE | TIME | DATE | TIMESTAMP | DATETIME |
BOOLEAN | BOOLEAN | BOOLEAN | TINYINT | SMALLINT | INTEGER | BIGINT | Not supported | DOUBLE | Not supported | Not supported | Not supported | Not supported |
TINYINT | BIGINT | TINYINT | TINYINT | SMALLINT | INTEGER | BIGINT | DECIMAL | DOUBLE | Not supported | Not supported | Not supported | Not supported |
SMALLINT | BIGINT | SMALLINT | SMALLINT | SMALLINT | INTEGER | BIGINT | DECIMAL | DOUBLE | Not supported | Not supported | Not supported | Not supported |
INTEGER | BIGINT | INTEGER | INTEGER | INTEGER | INTEGER | BIGINT | DECIMAL | DOUBLE | BIGINT | BIGINT | BIGINT | BIGINT |
BIGINT | BIGINT | BIGINT | BIGINT | BIGINT | BIGINT | BIGINT | DECIMAL | DOUBLE | BIGINT | BIGINT | BIGINT | BIGINT |
DECIMAL | DECIMAL | Not supported | DECIMAL | DECIMAL | DECIMAL | DECIMAL | DECIMAL | DOUBLE | Not supported | Not supported | Not supported | Not supported |
DOUBLE | DOUBLE | DOUBLE | DOUBLE | DOUBLE | DOUBLE | DOUBLE | DOUBLE | DOUBLE | DOUBLE | DOUBLE | DOUBLE | DOUBLE |
TIME | TIME | Not supported | Not supported | Not supported | BIGINT | BIGINT | Not supported | DOUBLE | TIME | BIGINT | BIGINT | DATETIME |
DATE | DATE | Not supported | Not supported | Not supported | BIGINT | BIGINT | Not supported | DOUBLE | BIGINT | TIMESTAMP | TIMESTAMP | DATETIME |
TIMESTAMP | TIMESTAMP | Not supported | Not supported | Not supported | BIGINT | BIGINT | Not supported | DOUBLE | BIGINT | TIMESTAMP | TIMESTAMP | DATETIME |
DATETIME | DATETIME | Not supported | Not supported | Not supported | BIGINT | BIGINT | Not supported | DOUBLE | DATETIME | DATETIME | DATETIME | DATETIME |
Filter conversion rules
When columns in WHERE clauses are compared with constants, the return types will be implicitly converted into the data types displayed in the following table. If implicit type conversion is not supported, an error occurs.
If the data types are different, implicit type conversion may result in pushdown failures, triggering a full table scan that significantly reduces query performance. Pushdown refers to pushing filter conditions to the storage layer for index-based filtering. This reduces data scanning loads when the filter degree is high, thereby improving query performance.
In the following table, 1 before the return data type indicates successful pushdown, and 0 indicates failed pushdown.
Column/Constant | VARCHAR | BOOLEAN | TINYINT | SMALLINT | INTEGER | BIGINT | DECIMAL | REAL | DOUBLE | TIME | DATE | TIMESTAMP | DATETIME |
VARCHAR | 1 VARCHAR | 0 BOOLEAN | 0 BIGINT | 0 BIGINT | 0 BIGINT | 0 BIGINT | 0 DECIMAL | 0 REAL | 0 DOUBLE | 0 TIME | 0 DATE | 0 TIMESTAMP | 0 DATETIME |
BOOLEAN | 1 BOOLEAN | 1 BOOLEAN | 0 TINYINT | 0 SMALLINT | 0 INTEGER | 0 BIGINT | Not supported | 0 REAL | 0 DOUBLE | Not supported | Not supported | Not supported | Not supported |
TINYINT | 1 TINYINT | 1 TINYINT | 1 TINYINT | 1 TINYINT | 1 TINYINT | 1 TINYINT | 0 DECIMAL | 0 REAL | 0 DOUBLE | Not supported | Not supported | Not supported | Not supported |
SMALLINT | 1 SMALLINT | 1 SMALLINT | 1 SMALLINT | 1 SMALLINT | 1 SMALLINT | 1 SMALLINT | 0 DECIMAL | 0 REAL | 0 DOUBLE | Not supported | Not supported | Not supported | Not supported |
INTEGER | 1 INTEGER | 1 INTEGER | 1 INTEGER | 1 INTEGER | 1 INTEGER | 1 INTEGER | 0 DECIMAL | 0 REAL | 0 DOUBLE | 1 INTEGER | 1 INTEGER | INTEGER | INTEGER |
BIGINT | 1 BIGINT | 1 BIGINT | 1 BIGINT | 1 BIGINT | 1 BIGINT | 1 BIGINT | 0 DECIMAL | 0 REAL | 0 DOUBLE | 1 BIGINT | 1 BIGINT | BIGINT | BIGINT |
DECIMAL | 1 DECIMAL | 1 DECIMAL | 1 DECIMAL | 1 DECIMAL | 1 DECIMAL | 1 DECIMAL | 1 DECIMAL | 0 REAL | 0 DOUBLE | Not supported | Not supported | Not supported | Not supported |
REAL | 1 REAL | 1 REAL | 1 REAL | 1 REAL | 1 REAL | 1 REAL | 1 REAL | 1 REAL | 0 DOUBLE | Not supported | Not supported | Not supported | Not supported |
DOUBLE | 1 DOUBLE | 1 DOUBLE | 1 DOUBLE | 1 DOUBLE | 1 DOUBLE | 1 DOUBLE | 1 DOUBLE | 1 DOUBLE | 1 DOUBLE | 1 DOUBLE | 1 DOUBLE | 1 DOUBLE | 1 DOUBLE |
TIME | 1 TIME | Not supported | Not supported | Not supported | 0 BIGINT | 0 BIGINT | Not supported | Not supported | 0 DOUBLE | 1 TIME | 0 BIGINT | 0 BIGINT | 0 DATETIME |
DATE | 1 DATE | Not supported | Not supported | Not supported | 0 BIGINT | 0 BIGINT | Not supported | Not supported | 0 DOUBLE | 0 BIGINT | 1 DATE | 0 TIMESTAMP | 0 DATETIME |
TIMESTAMP | 1 TIMESTAMP | Not supported | Not supported | Not supported | 0 BIGINT | 0 BIGINT | Not supported | Not supported | 0 DOUBLE | 1 TIMESTAMP | 1 TIMESTAMP | 1 TIMESTAMP | 1 TIMESTAMP |
DATETIME | 1 DATETIME | Not supported | Not supported | Not supported | 0 BIGINT | 0 BIGINT | Not supported | Not supported | 0 DOUBLE | 1 DATETIME | 1 DATETIME | 1 DATETIME | 1 DATETIME |
Forced type conversion optimization (ENFORCE_UNWRAP_CAST)
Forced type conversion optimization is used in database systems to control type conversion. It addresses query performance degradation and result accuracy issues caused by implicit type conversion.
Configuration methods
Forced type conversion optimization supports two configuration methods. You can choose one based on your business requirements.
Global configuration
Enable optimization by setting a global parameter, which applies to all queries.
SET ADB_CONFIG ENFORCE_UNWRAP_CAST = true;Hint configuration
Temporarily enable optimization for specific queries without affecting other queries.
/*+ ENFORCE_UNWRAP_CAST=true */
Example
The col column in the test table is of the VARCHAR type and contains the '1', '1a', and 'abc' values. Execute the following statement:
SELECT col FROM test WHERE col = 1;The result varies based on the configuration status of the enforce_unwrap_cast parameter.
Default disabled status (
ENFORCE_UNWRAP_CAST=false): The system implicitly converts the VARCHAR column to the BIGINT type for comparison. In this case,'1'and'1a'are truncated, and the non-numeric part is converted to the numeric value 1 for comparison. Two matching results,'1'and'1a', are returned. Because implicit type conversion is performed on column values, pushdown optimization fails to be triggered, and the system needs to scan the entire table. In this case, query performance decreases.Enabled status (
ENFORCE_UNWRAP_CAST=true): The system converts the INTEGER constant to the VARCHAR type for string comparison. In this case, only'1'matches the constant1, and'1a'is filtered out due to string mismatch. Only one matching result,'1', is returned. This optimization policy can push down the comparison logic to the storage layer, which effectively reduces the amount of data scanned and improves query performance.