You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DECIMAL(P[,S]) is a high-precision fixed-point value. `P` stands for the total number of significant numbers (precision). `S` stands for the maximum number of decimal points (scale).
8
8
9
-
If `P` is omitted, the default is 10. If `S` is omitted, the default is 0.
9
+
If `P` is omitted, the default value is 10. If `S` is omitted, the default value is 0.
10
10
11
-
* Decimal V2
11
+
- For versions earlier than v4.0, StarRocks supports DECIMAL128 based on [Fast DECIMAL](#fast-decimal).
12
+
- For v4.0 and later versions, StarRocks supports [DECIMAL256](#decimal256).
12
13
13
-
The range of `P` is [1,27] and the range of `S` is [0,9]. `P` must be greater than or equal to the value of `S`. The default value of `S` is 0.
14
+
## Features
14
15
15
-
* Fast Decimal (Decimal V3)
16
+
###Fast DECIMAL
16
17
17
-
The range of `P` is [1,38] and the range of `S` is [0, P]. The default value of `S` is 0. Fast Decimal provides a higher precision.
18
-
19
-
Major optimizations:
20
-
21
-
1. Fast Decimal uses variable-width integers to express decimals. For example, it uses 64-bit integers to express decimals whose precision is less than or equal to 18. Whereas, Decimal V2 uses 128-bit integers uniformly for all decimals. Arithmetic operations and conversion operations on 64-bit processors use fewer instructions, which greatly improves performance.
22
-
23
-
2. Compared with Decimal V2, Fast Decimal made significant optimizations in some algorithms, especially in multiplication, which improves performance by about 4 times.
18
+
Controlled by the FE dynamic parameter `enable_decimal_v3`, Fast DECIMAL is enabled by default.
24
19
25
-
Fast Decimal is controlled by the FE dynamic parameter `enable_decimal_v3`, which is `true` by default.
20
+
For Fast DECIMAL, the range of `P` is [1,38] and the range of `S` is [0, P]. The default value of `S` is 0.
21
+
22
+
Fast DECIMAL uses variable-width integers to express decimals.
23
+
24
+
- Decimal(P ≤ 18, S)
25
+
- LogicalType: Decimal64
26
+
- Stored as: int64
27
+
- Delegate LogicalType: BIGINT
28
+
29
+
- Decimal(P > 18 & P ≤ 38, S)
30
+
- LogicalType: Decimal128
31
+
- Stored as: int128
32
+
- Delegate LogicalType: LARGEINT
26
33
27
34
From v3.1 onwards, StarRocks supports Fast Decimal entries in [ARRAY](../semi_structured/Array.md), [MAP](../semi_structured/Map.md), and [STRUCT](../semi_structured/STRUCT.md).
28
-
35
+
36
+
## DECIMAL256
37
+
38
+
StarRocks introduces DECIMAL256 from v4.0 onwards.
39
+
40
+
For DECIMAL256, the range of `P` is (38,76] and the range of `S` is [0, P]. The default value of `S` is 0.
41
+
42
+
DECIMAL256 expands the upper limit of precision to 76 bits. Its numerical capacity is 10³⁸ times higher than that of DECIMAL128, reducing the probability of overflow to a negligible level.
43
+
44
+
DECIMAL256 uses the same strategy to express decimals as that of Fast DECIMAL. In addition to the two decimal types mentioned above, it supports:
45
+
46
+
- Decimal(P > 38 & P ≤ 76, S)
47
+
- LogicalType: Decimal256
48
+
- Stored as: int256
49
+
- Delegate LogicalType: INT_256
50
+
51
+
The actual representable range of DECIMAL256 is `-57896044618658097711785492504343953926634992332820282019728792003956564819968` to `57896044618658097711785492504343953926634992332820282019728792003956564819967`.
52
+
53
+
#### Type casting operations
54
+
55
+
DECIMAL256 supports bidirectional type conversion between all types listed below:
Currently, DECIMAL256 supports these aggregation functions: `COUNT`, `COUNT DISTINCT`, `SUM`, `SUM DISTINCT`, `AVG`, `AVG DISTINCT`, `MAX`, `MIN`, and `ABS`.
67
+
68
+
#### Limitations
69
+
70
+
DECIMAL256 has the following limitations:
71
+
72
+
- Currently, DECIMAL256 does not support automatic precision scale-up for decimal operations.
73
+
74
+
For example, `DECIMAL128 * DECIMAL128` will not be automatically scaled up to DECIMAL256. DECIMAL256 features are only applied when `DECIMAL256` is explicitly specified as the operand either in the CREATE TABLE statement or using CAST (`SELECT CAST(p38s10 as DECIMAL(70, 30))`).
75
+
76
+
- DECIMAL256 does not support window functions.
77
+
78
+
- Aggregate tables do not support DECIMAL256 type.
79
+
29
80
## Examples
30
81
82
+
### Fast DECIMAL example
83
+
31
84
Define DECIMAL columns when creating a table.
32
85
33
-
```sql
86
+
```SQL
34
87
CREATETABLEdecimalDemo (
35
88
pk BIGINT(20) NOT NULL COMMENT "",
36
89
account DECIMAL(20,10) COMMENT ""
@@ -54,6 +107,40 @@ SELECT * FROM decimalDemo;
54
107
+------+-----------------+
55
108
```
56
109
57
-
## keywords
110
+
### DECIMAL256 example
111
+
112
+
Create a table with a DECIMAL256 type column.
113
+
114
+
```SQL
115
+
CREATETABLEtest_decimal256(
116
+
p50s48 DECIMAL(50, 48) COMMENT ""
117
+
);
118
+
```
119
+
120
+
INSERT different values:
121
+
122
+
```SQL
123
+
INSERT INTO test_decimal256(p50s48) SELECT1.222222;
124
+
```
125
+
126
+
This statement succeeds with the values written correctly.
127
+
128
+
```SQL
129
+
INSERT INTO test_decimal256(p50s48) SELECT11111111111111111111111111111111111111111111.222222;
130
+
```
131
+
132
+
This statement succeeds with the values written as NULL. Because the integer part and decimal part (which has 44 digits) with the specified scale (which is `48`) together exceed the maximum integer that can be represented by 256 bits, FE directly casts the value to NULL.
133
+
134
+
```SQL
135
+
INSERT INTO test_decimal256(p50s48) SELECT333;
136
+
```
137
+
138
+
This statement will be returned with an error `ERROR 1064 (HY000): Insert has filtered data`. Because the integer part and decimal part with the specified scale (which is `48`) together exceed the maximum value represented by a 50-digit integer, BE returns the error.
139
+
140
+
## Usage notes
141
+
142
+
You can set the system variable `sql_mode` to `ERROR_IF_OVERFLOW` to allow the system to return an error instead of NULL in the case of arithmetic overflow.
143
+
144
+
## Keywords
58
145
59
-
decimal, decimalv2, decimalv3, fast decimal
146
+
decimal, decimalv3, fast decimal, decimal128, decimal256
Copy file name to clipboardExpand all lines: docs/en/sql-reference/data-types/semi_structured/Array.md
-1Lines changed: 0 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,7 +60,6 @@ The following limits apply when you create ARRAY columns in StarRocks tables:
60
60
- In versions earlier than v2.1, you can create ARRAY columns only in Duplicate Key tables. From v2.1 onwards, you can also create ARRAY columns in other types of tables (Primary Key, Unique Key, Aggregate). Note that in an Aggregate table, you can create an ARRAY column only when the function used to aggregate data in that column is replace() or replace_if_not_null(). For more information, see [Aggregate table](../../../table_design/table_types/aggregate_table.md).
61
61
- ARRAY columns cannot be used as key columns.
62
62
- ARRAY columns cannot be used as partition keys (included in PARTITION BY) or bucketing keys (included in DISTRIBUTED BY).
63
-
- DECIMAL V3 is not supported in ARRAY.
64
63
- An array can have a maximum of 14-level nesting.
0 commit comments