Small_Materialized_Aggrates.md 1.8 KB
Newer Older
H
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12
# Small Materialized Aggragates

**SMA** (**S**mall **M**aterialized **A**ggrates) is used to speed up the query process on materialized data cube in TDengine. TDengine 3.0 gives more flexibility on the SMA configurations.

There are two kinds of SMA in TDengine:
1. Block-wise SMA
2. Time-range-wise SMA

<!-- 
```plantuml
    @startmindmap mind_map_test
    * SMA
H
Hongze Cheng 已提交
13 14
    ** Block-wise SMA
    ** Time-range-wise SMA
H
Hongze Cheng 已提交
15
    @endmindmap
H
Hongze Cheng 已提交
16
```  -->
H
Hongze Cheng 已提交
17

H
Hongze Cheng 已提交
18
![SMA in TDengine 3.0](http://www.plantuml.com/plantuml/png/Kr1GK70eBaaiAidDp4l9JInG0D7nG4PyIMfn2HTGMa5B8TZN4SBIKd3AoK_ErYtFB4v55Wt9p4tLBKhCIqz5bN981HeACHW0)
H
Hongze Cheng 已提交
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
## Block-wise SMA
Block-wise SMA is created by default when the data are committed. Since time-series data are saved as block data in files, a corresponding SMA is create when the data block is written. The default block-wise SMA includes:
1. sum(*)
2. max(*)
3. min(*)

By default, the system will create SMA for each column except those columns with type *binary* and *nchar*. However, users can change the behavior by the keyword **NOSMA** to disable the SMA for a certain column like below:
```SQL
# create a super table with the SMA on column b disabled
create table st (ts timestamp, a int, b int NOSMA, c double) tags (tg1 binary(10), tg2 int);
```

## Time-range-wise SMA
In addition to the default block-wise SMA, users can create their own SMAs ondemand. Below is an example to create a SMA.
```SQL
# create a SMA every 10 minutes with SMA of sum, max and min
H
change  
Hongze Cheng 已提交
35
create sma_indx sma_10min on st (sum(*), max(*), min(*), twa(*)) interval(10m);
H
Hongze Cheng 已提交
36 37 38 39 40 41
```
Users can also drop a time-range-wise SMA like below:
```SQL
# drop the sma index
drop sma_index sma_5min on st;
```
H
change  
Hongze Cheng 已提交
42
**NOTE: Creating an SMA index is a heavy operation which may take a long time and block the write operation. So create the time-range-wise SMA when creating the table or when there are not too much data.**