diff --git a/documentation/tdenginedocs-cn/super-table/index.html b/documentation/tdenginedocs-cn/super-table/index.html index 13e5cdd17370a1bc3a2e6659c8f529bed23eaefa..efc6fdace07db522075db33a58a9e6c46a313050 100644 --- a/documentation/tdenginedocs-cn/super-table/index.html +++ b/documentation/tdenginedocs-cn/super-table/index.html @@ -11,8 +11,8 @@ tags (location binary(20), type int)

为某个采集点创建表时,可以指定其所属的STable以及标签的值,语法如下:

CREATE TABLE <tb_name> USING <stb_name> TAGS (tag_value1,...)

沿用上面温度计的例子,使用超级表thermometer建立单个温度计数据表的语句如下:

-
create table t1 using thermometer tags (‘beijing’, 10)
-

上述SQL以thermometer为模板,创建了名为t1的表,这张表的Schema就是thermometer的Schema,但标签location值为‘beijing’,标签type值为10。

+
create table t1 using thermometer tags (‘beijing', 10)
+

上述SQL以thermometer为模板,创建了名为t1的表,这张表的Schema就是thermometer的Schema,但标签location值为'beijing',标签type值为10。

用户可以使用一个STable创建数量无上限的具有不同标签的表,从这个意义上理解,STable就是若干具有相同数据模型,不同标签的表的集合。与普通表一样,用户可以创建、删除、查看超级表STable,大部分适用于普通表的查询操作都可运用到STable上,包括各种聚合和投影选择函数。除此之外,可以设置标签的过滤条件,仅对STbale中部分表进行聚合查询,大大简化应用的开发。

TDengine对表的主键(时间戳)建立索引,暂时不提供针对数据模型中其他采集量(比如温度、压力值)的索引。每个数据采集点会采集若干数据记录,但每个采集点的标签仅仅是一条记录,因此数据标签在存储上没有冗余,且整体数据规模有限。TDengine将标签数据与采集的动态数据完全分离存储,而且针对STable的标签建立了高性能内存索引结构,为标签提供全方位的快速操作支持。用户可按照需求对其进行增删改查(Create,Retrieve,Update,Delete,CRUD)操作。

STable从属于库,一个STable只属于一个库,但一个库可以有一到多个STable, 一个STable可有多个子表。

@@ -84,27 +84,27 @@ tags (location binary(20), type int)
CREATE TABLE thermometer (ts timestamp, degree double) 
 TAGS(location binary(20), type int)

假设有北京,天津和上海三个地区的采集器共4个,温度采集器有3种类型,我们就可以对每个采集器建表如下:

-
CREATE TABLE therm1 USING thermometer TAGS (’beijing’, 1);
-CREATE TABLE therm2 USING thermometer TAGS (’beijing’, 2);
-CREATE TABLE therm3 USING thermometer TAGS (’tianjin’, 1);
-CREATE TABLE therm4 USING thermometer TAGS (’shanghai’, 3);
+
CREATE TABLE therm1 USING thermometer TAGS ('beijing', 1);
+CREATE TABLE therm2 USING thermometer TAGS ('beijing', 2);
+CREATE TABLE therm3 USING thermometer TAGS ('tianjin', 1);
+CREATE TABLE therm4 USING thermometer TAGS ('shanghai', 3);

其中therm1,therm2,therm3,therm4是超级表thermometer四个具体的子表,也即普通的Table。以therm1为例,它表示采集器therm1的数据,表结构完全由thermometer定义,标签location=”beijing”, type=1表示therm1的地区是北京,类型是第1类的温度计。

写入数据

注意,写入数据时不能直接对STable操作,而是要对每张子表进行操作。我们分别向四张表therm1,therm2, therm3, therm4写入一条数据,写入语句如下:

-
INSERT INTO therm1 VALUES (’2018-01-01 00:00:00.000’, 20);
-INSERT INTO therm2 VALUES (’2018-01-01 00:00:00.000’, 21);
-INSERT INTO therm3 VALUES (’2018-01-01 00:00:00.000’, 24);
-INSERT INTO therm4 VALUES (’2018-01-01 00:00:00.000’, 23);
+
INSERT INTO therm1 VALUES ('2018-01-01 00:00:00.000', 20);
+INSERT INTO therm2 VALUES ('2018-01-01 00:00:00.000', 21);
+INSERT INTO therm3 VALUES ('2018-01-01 00:00:00.000', 24);
+INSERT INTO therm4 VALUES ('2018-01-01 00:00:00.000', 23);

按标签聚合查询

查询位于北京(beijing)和天津(tianjing)两个地区的温度传感器采样值的数量count(*)、平均温度avg(degree)、最高温度max(degree)、最低温度min(degree),并将结果按所处地域(location)和传感器类型(type)进行聚合。

SELECT COUNT(*), AVG(degree), MAX(degree), MIN(degree)
 FROM thermometer
-WHERE location=’beijing’ or location=’tianjing’
+WHERE location='beijing' or location='tianjin'
 GROUP BY location, type 

按时间周期聚合查询

查询仅位于北京以外地区的温度传感器最近24小时(24h)采样值的数量count(*)、平均温度avg(degree)、最高温度max(degree)和最低温度min(degree),将采集结果按照10分钟为周期进行聚合,并将结果按所处地域(location)和传感器类型(type)再次进行聚合。

SELECT COUNT(*), AVG(degree), MAX(degree), MIN(degree)
 FROM thermometer
-WHERE name<>’beijing’ and ts>=now-1d
+WHERE name<>'beijing' and ts>=now-1d
 INTERVAL(10M)
 GROUP BY location, type
回去 \ No newline at end of file diff --git a/documentation/tdenginedocs-en/super-table/index.html b/documentation/tdenginedocs-en/super-table/index.html index 0c68df7d0048e2fb88606ce61f222f76ccee67d2..53cd69432360dbd7d6dc346bee15eca3f81463ff 100644 --- a/documentation/tdenginedocs-en/super-table/index.html +++ b/documentation/tdenginedocs-en/super-table/index.html @@ -24,11 +24,11 @@ tags (location binary(20), type int)

To create a table for a device, you can use a STable as its template and assign the tag values. The syntax is:

CREATE TABLE <tb_name> USING <stb_name> TAGS (tag_value1,...)

You can create any number of tables via a STable, and each table may have different tag values. For example, you create five tables via STable thermometer below:

-
 create table t1 using thermometer tags (‘beijing’, 10);
- create table t2 using thermometer tags (‘beijing’, 20);
- create table t3 using thermometer tags (‘shanghai’, 10);
- create table t4 using thermometer tags (‘shanghai’, 20);
- create table t5 using thermometer tags (‘new york’, 10);
+
 create table t1 using thermometer tags ('beijing', 10);
+ create table t2 using thermometer tags ('beijing', 20);
+ create table t3 using thermometer tags ('shanghai', 10);
+ create table t4 using thermometer tags ('shanghai', 20);
+ create table t5 using thermometer tags ('new york', 10);

Aggregate Tables via STable

You can group a set of tables together by specifying the tags filter condition, then apply the aggregation operations. The result set can be grouped and ordered based on tag value. Syntax is:

SELECT function<field_name>,… 
@@ -51,13 +51,13 @@ tags (location binary(20), type int)

Check the average, maximum, and minimum temperatures of Beijing and Shanghai, and group the result set by location and type. The SQL statement shall be:

SELECT COUNT(*), AVG(degree), MAX(degree), MIN(degree)
 FROM thermometer
-WHERE location=’beijing’ or location=’tianjing’
+WHERE location='beijing' or location='tianjin'
 GROUP BY location, type 

Example 2:

List the number of records, average, maximum, and minimum temperature every 10 minutes for the past 24 hours for all the thermometers located in Beijing with type 10. The SQL statement shall be:

SELECT COUNT(*), AVG(degree), MAX(degree), MIN(degree)
 FROM thermometer
-WHERE name=’beijing’ and type=10 and ts>=now-1d
+WHERE name='beijing' and type=10 and ts>=now-1d
 INTERVAL(10M)

Create Table Automatically

Insert operation will fail if the table is not created yet. But for STable, TDengine can create the table automatically if the application provides the STable name, table name and tags' value when inserting data points. The syntax is:

diff --git a/documentation/webdocs/markdowndocs/Super Table-ch.md b/documentation/webdocs/markdowndocs/Super Table-ch.md index 039ba3359e65691e58453693bd146ab1e457f8c4..fa32e3954b7cc37ee71e9cb4dffe3fa1e53c7602 100644 --- a/documentation/webdocs/markdowndocs/Super Table-ch.md +++ b/documentation/webdocs/markdowndocs/Super Table-ch.md @@ -30,10 +30,10 @@ CREATE TABLE USING TAGS (tag_value1,...) 沿用上面温度计的例子,使用超级表thermometer建立单个温度计数据表的语句如下: ```mysql -create table t1 using thermometer tags (‘beijing’, 10) +create table t1 using thermometer tags (‘beijing', 10) ``` -上述SQL以thermometer为模板,创建了名为t1的表,这张表的Schema就是thermometer的Schema,但标签location值为‘beijing’,标签type值为10。 +上述SQL以thermometer为模板,创建了名为t1的表,这张表的Schema就是thermometer的Schema,但标签location值为'beijing',标签type值为10。 用户可以使用一个STable创建数量无上限的具有不同标签的表,从这个意义上理解,STable就是若干具有相同数据模型,不同标签的表的集合。与普通表一样,用户可以创建、删除、查看超级表STable,大部分适用于普通表的查询操作都可运用到STable上,包括各种聚合和投影选择函数。除此之外,可以设置标签的过滤条件,仅对STbale中部分表进行聚合查询,大大简化应用的开发。 @@ -181,10 +181,10 @@ TAGS(location binary(20), type int) 假设有北京,天津和上海三个地区的采集器共4个,温度采集器有3种类型,我们就可以对每个采集器建表如下: ```mysql -CREATE TABLE therm1 USING thermometer TAGS (’beijing’, 1); -CREATE TABLE therm2 USING thermometer TAGS (’beijing’, 2); -CREATE TABLE therm3 USING thermometer TAGS (’tianjin’, 1); -CREATE TABLE therm4 USING thermometer TAGS (’shanghai’, 3); +CREATE TABLE therm1 USING thermometer TAGS ('beijing', 1); +CREATE TABLE therm2 USING thermometer TAGS ('beijing', 2); +CREATE TABLE therm3 USING thermometer TAGS ('tianjin', 1); +CREATE TABLE therm4 USING thermometer TAGS ('shanghai', 3); ``` 其中therm1,therm2,therm3,therm4是超级表thermometer四个具体的子表,也即普通的Table。以therm1为例,它表示采集器therm1的数据,表结构完全由thermometer定义,标签location=”beijing”, type=1表示therm1的地区是北京,类型是第1类的温度计。 @@ -194,10 +194,10 @@ CREATE TABLE therm4 USING thermometer TAGS (’shanghai’, 3); 注意,写入数据时不能直接对STable操作,而是要对每张子表进行操作。我们分别向四张表therm1,therm2, therm3, therm4写入一条数据,写入语句如下: ```mysql -INSERT INTO therm1 VALUES (’2018-01-01 00:00:00.000’, 20); -INSERT INTO therm2 VALUES (’2018-01-01 00:00:00.000’, 21); -INSERT INTO therm3 VALUES (’2018-01-01 00:00:00.000’, 24); -INSERT INTO therm4 VALUES (’2018-01-01 00:00:00.000’, 23); +INSERT INTO therm1 VALUES ('2018-01-01 00:00:00.000', 20); +INSERT INTO therm2 VALUES ('2018-01-01 00:00:00.000', 21); +INSERT INTO therm3 VALUES ('2018-01-01 00:00:00.000', 24); +INSERT INTO therm4 VALUES ('2018-01-01 00:00:00.000', 23); ``` ### 按标签聚合查询 @@ -207,7 +207,7 @@ INSERT INTO therm4 VALUES (’2018-01-01 00:00:00.000’, 23); ```mysql SELECT COUNT(*), AVG(degree), MAX(degree), MIN(degree) FROM thermometer -WHERE location=’beijing’ or location=’tianjing’ +WHERE location='beijing' or location='tianjin' GROUP BY location, type ``` @@ -218,7 +218,7 @@ GROUP BY location, type ```mysql SELECT COUNT(*), AVG(degree), MAX(degree), MIN(degree) FROM thermometer -WHERE name<>’beijing’ and ts>=now-1d +WHERE name<>'beijing' and ts>=now-1d INTERVAL(10M) GROUP BY location, type ``` \ No newline at end of file diff --git a/documentation/webdocs/markdowndocs/Super Table.md b/documentation/webdocs/markdowndocs/Super Table.md index 98e8209458fb266434f87e78787daf7d1b3479f4..c971309c90db80dfb6c0cecefa2a12808341ce9b 100644 --- a/documentation/webdocs/markdowndocs/Super Table.md +++ b/documentation/webdocs/markdowndocs/Super Table.md @@ -48,11 +48,11 @@ CREATE TABLE USING TAGS (tag_value1,...) You can create any number of tables via a STable, and each table may have different tag values. For example, you create five tables via STable thermometer below: ```mysql - create table t1 using thermometer tags (‘beijing’, 10); - create table t2 using thermometer tags (‘beijing’, 20); - create table t3 using thermometer tags (‘shanghai’, 10); - create table t4 using thermometer tags (‘shanghai’, 20); - create table t5 using thermometer tags (‘new york’, 10); + create table t1 using thermometer tags ('beijing', 10); + create table t2 using thermometer tags ('beijing', 20); + create table t3 using thermometer tags ('shanghai', 10); + create table t4 using thermometer tags ('shanghai', 20); + create table t5 using thermometer tags ('new york', 10); ``` ## Aggregate Tables via STable @@ -91,7 +91,7 @@ Check the average, maximum, and minimum temperatures of Beijing and Shanghai, an ```mysql SELECT COUNT(*), AVG(degree), MAX(degree), MIN(degree) FROM thermometer -WHERE location=’beijing’ or location=’tianjing’ +WHERE location='beijing' or location='tianjin' GROUP BY location, type ``` @@ -102,7 +102,7 @@ List the number of records, average, maximum, and minimum temperature every 10 m ```mysql SELECT COUNT(*), AVG(degree), MAX(degree), MIN(degree) FROM thermometer -WHERE name=’beijing’ and type=10 and ts>=now-1d +WHERE name='beijing' and type=10 and ts>=now-1d INTERVAL(10M) ```