# STable: Super Table "One Table for One Device" design can improve the insert/query performance significantly for a single device. But it has a side effect, the aggregation of multiple tables becomes hard. To reduce the complexity and improve the efficiency, TDengine introduced a new concept: STable (Super Table). ## What is a Super Table STable is an abstract and a template for a type of device. A STable contains a set of devices (tables) that have the same schema or data structure. Besides the shared schema, a STable has a set of tags, like the model, serial number and so on. Tags are used to record the static attributes for the devices and are used to group a set of devices (tables) for aggregation. Tags are metadata of a table and can be added, deleted or changed. TDengine does not save tags as a part of the data points collected. Instead, tags are saved as metadata. Each table has a set of tags. To improve query performance, tags are all cached and indexed. One table can only belong to one STable, but one STable may contain many tables. Like a table, you can create, show, delete and describe STables. Most query operations on tables can be applied to STable too, including the aggregation and selector functions. For queries on a STable, if no tags filter, the operations are applied to all the tables created via this STable. If there is a tag filter, the operations are applied only to a subset of the tables which satisfy the tag filter conditions. It will be very convenient to use tags to put devices into different groups for aggregation. ## Create a STable Similiar to creating a standard table, syntax is: ```mysql CREATE TABLE ( TIMESTAMP, field_name1 field_type,…) TAGS(tag_name tag_type, …) ``` New keyword "tags" is introduced, where tag_name is the tag name, and tag_type is the associated data type. Note: 1. The bytes of all tags together shall be less than 16k 2. Tag's data type can not be time stamp 3. Tag name shall be different from the field name 4. Tag name shall not be the same as system keywords 5. Maximum number of tags is 128 For example: ```mysql create table thermometer (ts timestamp, degree float) tags (location binary(20), type int) ``` The above statement creates a STable thermometer with two tag "location" and "type" ## Create a Table via STable To create a table for a device, you can use a STable as its template and assign the tag values. The syntax is: ```mysql 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); ``` ## 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: ```mysql SELECT function,… FROM WHERE <[=|<=|>=|<>] values..> ([AND|OR] …) INTERVAL (