文档说明

Influx Query Language (InfluxQL) 参考

简介

InfluxQL 是一种类似于 SQL 的查询语言,用于与 InfluxDB 交互并提供针对存储和分析时间序列数据的功能。

查找 Influx Query Language (InfluxQL) 定义和详细信息,包括

要了解更多关于 InfluxQL 的信息,请浏览以下主题

符号

语法使用扩展 Backus-Naur 形式(“EBNF”)指定。EBNF 与在 Go 编程语言规范中使用的符号相同,可以在 此处 找到。

Production  = production_name "=" [ Expression ] "." .
Expression  = Alternative { "|" Alternative } .
Alternative = Term { Term } .
Term        = production_name | token [ "…" token ] | Group | Option | Repetition .
Group       = "(" Expression ")" .
Option      = "[" Expression "]" .
Repetition  = "{" Expression "}" .

按优先级顺序排列的符号运算符

|   alternation
()  grouping
[]  option (0 or 1 times)
{}  repetition (0 to n times)

查询表示

字符

InfluxQL 是使用 UTF-8 编码的 Unicode 文本。

newline             = /* the Unicode code point U+000A */ .
unicode_char        = /* an arbitrary Unicode code point except newline */ .

字母和数字

字母是 ASCII 字符集加上下划线字符 _(U+005F),被认为是字母。

仅支持十进制数字。

letter              = ascii_letter | "_" .
ascii_letter        = "A" … "Z" | "a" … "z" .
digit               = "0" … "9" .

标识符

标识符是引用数据库名称、保留策略名称、用户名称、度量名称、标签键和字段键的标记。

规则

  • 双引号标识符可以包含任何除了换行符之外的 Unicode 字符
  • 双引号标识符可以包含转义的双引号字符(即,\"
  • 双引号标识符可以包含 InfluxQL 关键字
  • 未引用的标识符必须以大写或小写 ASCII 字符或“_”开头
  • 未引用的标识符可以包含 ASCII 字母、十进制数字和“_”
identifier          = unquoted_identifier | quoted_identifier .
unquoted_identifier = ( letter ) { letter | digit } .
quoted_identifier   = `"` unicode_char { unicode_char } `"` .

示例

cpu
_cpu_stats
"1h"
"anything really"
"1_Crazy-1337.identifier>NAME👍"

关键字

ALL           ALTER         ANY           AS            ASC           BEGIN
BY            CREATE        CONTINUOUS    DATABASE      DATABASES     DEFAULT
DELETE        DESC          DESTINATIONS  DIAGNOSTICS   DISTINCT      DROP
DURATION      END           EVERY         EXPLAIN       FIELD         FOR
FROM          GRANT         GRANTS        GROUP         GROUPS        IN
INF           INSERT        INTO          KEY           KEYS          KILL
LIMIT         SHOW          MEASUREMENT   MEASUREMENTS  NAME          OFFSET
ON            ORDER         PASSWORD      POLICY        POLICIES      PRIVILEGES
QUERIES       QUERY         READ          REPLICATION   RESAMPLE      RETENTION
REVOKE        SELECT        SERIES        SET           SHARD         SHARDS
SLIMIT        SOFFSET       STATS         SUBSCRIPTION  SUBSCRIPTIONS TAG
TO            USER          USERS         VALUES        WHERE         WITH
WRITE

如果您将 InfluxQL 关键字用作 标识符,则需要在每个查询中对该标识符进行双引号引用。

关键字 time 是一个特殊情况。time 可以是 连续查询 名称、数据库名称、度量 名称、保留策略 名称、订阅 名称和 用户 名称。在这些情况下,time 在查询中不需要双引号。time 不能是 字段键标签键;InfluxDB 拒绝以 time 作为字段键或标签键的写入,并返回错误。有关更多信息,请参阅 常见问题解答

字面量

整数

InfluxQL 支持十进制整数字面量。目前不支持十六进制和八进制字面量。

int_lit             = ( "1" … "9" ) { digit } .

浮点数

InfluxQL 支持浮点数字面量。目前不支持指数。

float_lit           = int_lit "." int_lit .

字符串

字符串字面量必须用单引号包围。只要它们是转义的(即\'),字符串中可以包含'字符。

string_lit          = `'` { unicode_char } `'` .

持续时间

持续时间字面量指定了一段时间的长度。一个整数字面量后面立即(没有空格)跟以下列出的持续时间单位被解释为持续时间字面量。持续时间可以用混合的单位指定。

持续时间单位
单位含义
ns纳秒(一秒的十亿分之一)
u 或 µ微秒(一秒的一百万分之一)
ms毫秒(一秒的一千分之一)
s
m分钟
h小时
d
w
duration_lit        = int_lit duration_unit .
duration_unit       = "ns" | "u" | "µ" | "ms" | "s" | "m" | "h" | "d" | "w" .

日期 & 时间

日期和时间的字面量格式在本文档的其他部分没有像EBNF那样指定。它使用Go的日期/时间解析格式指定,该格式是InfluxQL所需格式的参考日期。参考日期时间是

InfluxQL参考日期时间:2006年1月2日 3:04:05 PM

time_lit            = "2006-01-02 15:04:05.999999" | "2006-01-02" .

布尔值

bool_lit            = TRUE | FALSE .

正则表达式

regex_lit           = "/" { unicode_char } "/" .

比较器: =~ 匹配,!~ 不匹配

注意: InfluxQL支持在指定

目前,InfluxQL不支持在WHERE子句、数据库保留策略 中使用正则表达式匹配非字符串字段值。

查询

一个查询由一个或多个用分号分隔的语句组成。

query               = statement { ";" statement } .

statement           = alter_retention_policy_stmt |
                      create_continuous_query_stmt |
                      create_database_stmt |
                      create_retention_policy_stmt |
                      create_subscription_stmt |
                      create_user_stmt |
                      delete_stmt |
                      drop_continuous_query_stmt |
                      drop_database_stmt |
                      drop_measurement_stmt |
                      drop_retention_policy_stmt |
                      drop_series_stmt |
                      drop_shard_stmt |
                      drop_subscription_stmt |
                      drop_user_stmt |
                      explain_stmt |
                      explain_analyze_stmt |
                      grant_stmt |
                      kill_query_statement |
                      revoke_stmt |
                      select_stmt |
                      show_continuous_queries_stmt |
                      show_databases_stmt |
                      show_diagnostics_stmt |
                      show_field_key_cardinality_stmt |
                      show_field_keys_stmt |
                      show_grants_stmt |
                      show_measurement_cardinality_stmt |
                      show_measurement_exact_cardinality_stmt |
                      show_measurements_stmt |
                      show_queries_stmt |
                      show_retention_policies_stmt |
                      show_series_cardinality_stmt |
                      show_series_exact_cardinality_stmt |
                      show_series_stmt |
                      show_shard_groups_stmt |
                      show_shards_stmt |
                      show_stats_stmt |
                      show_subscriptions_stmt |
                      show_tag_key_cardinality_stmt |
                      show_tag_key_exact_cardinality_stmt |
                      show_tag_keys_stmt |
                      show_tag_values_stmt |
                      show_tag_values_cardinality_stmt |
                      show_users_stmt .

语句

ALTER RETENTION POLICY

alter_retention_policy_stmt  = "ALTER RETENTION POLICY" policy_name on_clause
                               retention_policy_option
                               [ retention_policy_option ]
                               [ retention_policy_option ]
                               [ retention_policy_option ] .

示例

-- Set default retention policy for mydb to 1h.cpu.
ALTER RETENTION POLICY "1h.cpu" ON "mydb" DEFAULT

-- Change duration and replication factor.
-- REPLICATION (replication factor) not valid for OSS instances.
ALTER RETENTION POLICY "policy1" ON "somedb" DURATION 1h REPLICATION 4

CREATE CONTINUOUS QUERY

create_continuous_query_stmt = "CREATE CONTINUOUS QUERY" query_name on_clause
                               [ "RESAMPLE" resample_opts ]
                               "BEGIN" select_stmt "END" .

query_name                   = identifier .

resample_opts                = (every_stmt for_stmt | every_stmt | for_stmt) .
every_stmt                   = "EVERY" duration_lit
for_stmt                     = "FOR" duration_lit

示例

-- selects from DEFAULT retention policy and writes into 6_months retention policy
CREATE CONTINUOUS QUERY "10m_event_count"
ON "db_name"
BEGIN
  SELECT count("value")
  INTO "6_months"."events"
  FROM "events"
  GROUP (10m)
END;

-- this selects from the output of one continuous query in one retention policy and outputs to another series in another retention policy
CREATE CONTINUOUS QUERY "1h_event_count"
ON "db_name"
BEGIN
  SELECT sum("count") as "count"
  INTO "2_years"."events"
  FROM "6_months"."events"
  GROUP BY time(1h)
END;

-- this customizes the resample interval so the interval is queried every 10s and intervals are resampled until 2m after their start time
-- when resample is used, at least one of "EVERY" or "FOR" must be used
CREATE CONTINUOUS QUERY "cpu_mean"
ON "db_name"
RESAMPLE EVERY 10s FOR 2m
BEGIN
  SELECT mean("value")
  INTO "cpu_mean"
  FROM "cpu"
  GROUP BY time(1m)
END;

CREATE DATABASE

create_database_stmt = "CREATE DATABASE" db_name
                       [ WITH
                           [ retention_policy_duration ]
                           [ retention_policy_replication ]
                           [ retention_policy_shard_group_duration ]
                           [ retention_policy_name ]
                       ] .

副本因子对于单节点实例没有作用。

示例

-- Create a database called foo
CREATE DATABASE "foo"

-- Create a database called bar with a new DEFAULT retention policy and specify the duration, replication, shard group duration, and name of that retention policy
CREATE DATABASE "bar" WITH DURATION 1d REPLICATION 1 SHARD DURATION 30m NAME "myrp"

-- Create a database called mydb with a new DEFAULT retention policy and specify the name of that retention policy
CREATE DATABASE "mydb" WITH NAME "myrp"

CREATE RETENTION POLICY

create_retention_policy_stmt = "CREATE RETENTION POLICY" policy_name on_clause
                               retention_policy_duration
                               retention_policy_replication
                               [ retention_policy_shard_group_duration ]
                               [ "DEFAULT" ] .

副本因子对于单节点实例没有作用。

示例

-- Create a retention policy.
CREATE RETENTION POLICY "10m.events" ON "somedb" DURATION 60m REPLICATION 2

-- Create a retention policy and set it as the DEFAULT.
CREATE RETENTION POLICY "10m.events" ON "somedb" DURATION 60m REPLICATION 2 DEFAULT

-- Create a retention policy and specify the shard group duration.
CREATE RETENTION POLICY "10m.events" ON "somedb" DURATION 60m REPLICATION 2 SHARD DURATION 30m

CREATE SUBSCRIPTION

订阅告诉InfluxDB将接收到的所有数据发送到 Kapacitor

create_subscription_stmt = "CREATE SUBSCRIPTION" subscription_name "ON" db_name "." retention_policy "DESTINATIONS" ("ANY"|"ALL") host { "," host} .

示例

-- Create a SUBSCRIPTION on database 'mydb' and retention policy 'autogen' that send data to 'example.com:9090' via UDP.
CREATE SUBSCRIPTION "sub0" ON "mydb"."autogen" DESTINATIONS ALL 'udp://example.com:9090'

-- Create a SUBSCRIPTION on database 'mydb' and retention policy 'autogen' that round robins the data to 'h1.example.com:9090' and 'h2.example.com:9090'.
CREATE SUBSCRIPTION "sub0" ON "mydb"."autogen" DESTINATIONS ANY 'udp://h1.example.com:9090', 'udp://h2.example.com:9090'

CREATE USER

create_user_stmt = "CREATE USER" user_name "WITH PASSWORD" password
                   [ "WITH ALL PRIVILEGES" ] .

示例

-- Create a normal database user.
CREATE USER "jdoe" WITH PASSWORD '1337password'

-- Create an admin user.
-- Note: Unlike the GRANT statement, the "PRIVILEGES" keyword is required here.
CREATE USER "jdoe" WITH PASSWORD '1337password' WITH ALL PRIVILEGES

注意: 密码字符串必须用单引号括起来。

DELETE

delete_stmt = "DELETE" ( from_clause | where_clause | from_clause where_clause ) .

示例

DELETE FROM "cpu"
DELETE FROM "cpu" WHERE time < '2000-01-01T00:00:00Z'
DELETE WHERE time < '2000-01-01T00:00:00Z'

DROP CONTINUOUS QUERY

drop_continuous_query_stmt = "DROP CONTINUOUS QUERY" query_name on_clause .

示例

DROP CONTINUOUS QUERY "myquery" ON "mydb"

DROP DATABASE

drop_database_stmt = "DROP DATABASE" db_name .

示例

DROP DATABASE "mydb"

DROP MEASUREMENT

drop_measurement_stmt = "DROP MEASUREMENT" measurement .

示例

-- drop the cpu measurement
DROP MEASUREMENT "cpu"

DROP RETENTION POLICY

drop_retention_policy_stmt = "DROP RETENTION POLICY" policy_name on_clause .

示例

-- drop the retention policy named 1h.cpu from mydb
DROP RETENTION POLICY "1h.cpu" ON "mydb"

DROP SERIES

drop_series_stmt = "DROP SERIES" ( from_clause | where_clause | from_clause where_clause ) .

注意:WHERE子句中不支持按时间过滤。

示例

DROP SERIES FROM "telegraf"."autogen"."cpu" WHERE cpu = 'cpu8'

DROP SHARD

drop_shard_stmt = "DROP SHARD" ( shard_id ) .

示例

DROP SHARD 1

DROP SUBSCRIPTION

drop_subscription_stmt = "DROP SUBSCRIPTION" subscription_name "ON" db_name "." retention_policy .

示例

DROP SUBSCRIPTION "sub0" ON "mydb"."autogen"

DROP USER

drop_user_stmt = "DROP USER" user_name .

示例

DROP USER "jdoe"

EXPLAIN

解析并计划查询,然后打印估计成本的摘要。

许多SQL引擎使用EXPLAIN语句来显示连接顺序、连接算法以及谓词和表达式下推。由于InfluxQL不支持连接,InfluxQL查询的成本通常是访问的总系列数量、访问TSM文件的迭代器次数以及需要扫描的TSM块数量的函数。

EXPLAIN查询计划包括以下元素

  • 表达式
  • 辅助字段
  • 分片数量
  • 系列数量
  • 缓存值
  • 文件数量
  • 块数量
  • 块大小
explain_stmt = "EXPLAIN" select_stmt .

示例

> explain select sum(pointReq) from "_internal"."monitor"."write" group by hostname;
> QUERY PLAN
------
EXPRESSION: sum(pointReq::integer)
NUMBER OF SHARDS: 2
NUMBER OF SERIES: 2
CACHED VALUES: 110
NUMBER OF FILES: 1
NUMBER OF BLOCKS: 1
SIZE OF BLOCKS: 931

EXPLAIN ANALYZE

执行指定的SELECT语句并在运行时返回查询性能和存储的数据,以树状图的形式可视化。使用此语句来分析查询性能和存储,包括执行时间规划时间,以及迭代器类型游标类型

例如,执行以下语句

> explain analyze select mean(usage_steal) from cpu where time >= '2018-02-22T00:00:00Z' and time < '2018-02-22T12:00:00Z'

可能产生类似于以下输出的结果

EXPLAIN ANALYZE
---------------
.
└── select
    ├── execution_time: 2.25823ms
    ├── planning_time: 18.381616ms
    ├── total_time: 20.639846ms
    └── field_iterators
        ├── labels
           └── statement: SELECT mean(usage_steal::float) FROM telegraf."default".cpu
        └── expression
            ├── labels
               └── expr: mean(usage_steal::float)
            └── create_iterator
                ├── labels
                   ├── measurement: cpu
                   └── shard_id: 608
                ├── cursors_ref: 779
                ├── cursors_aux: 0
                ├── cursors_cond: 0
                ├── float_blocks_decoded: 431
                ├── float_blocks_size_bytes: 1003552
                ├── integer_blocks_decoded: 0
                ├── integer_blocks_size_bytes: 0
                ├── unsigned_blocks_decoded: 0
                ├── unsigned_blocks_size_bytes: 0
                ├── string_blocks_decoded: 0
                ├── string_blocks_size_bytes: 0
                ├── boolean_blocks_decoded: 0
                ├── boolean_blocks_size_bytes: 0
                └── planning_time: 14.805277ms```

注意:EXPLAIN ANALYZE忽略了查询输出,因此序列化为JSON或CSV的成本不计入。

execution_time

显示查询执行所需的时间,包括读取时间序列数据、在数据流通过迭代器时执行操作以及从迭代器中排空处理后的数据。执行时间不包括将输出序列化为JSON或其他格式所需的时间。

planning_time

显示查询规划所需的时间。在InfluxDB中规划查询需要多个步骤。根据查询的复杂度,规划可能需要更多工作,并消耗比执行查询更多的CPU和内存资源。例如,执行查询所需的系列键的数量会影响查询规划的快速程度和所需的内存。

首先,InfluxDB确定查询的有效时间范围并选择要访问的分片(在InfluxDB Enterprise中,分片可能位于远程节点上)。然后,对于每个分片和每个度量,InfluxDB执行以下步骤

  1. 从索引中选择匹配的系列键,通过WHERE子句中的标签谓词进行过滤。
  2. 根据GROUP BY维度将过滤后的系列键分组到标签集中。
  3. 枚举每个标签集并为每个系列键创建一个游标和迭代器。
  4. 合并迭代器并将合并后的结果返回给查询执行器。
iterator类型

EXPLAIN ANALYZE支持以下迭代器类型

  • create_iterator节点表示本地influxd实例完成的工作──一个复杂的嵌套迭代器组合和合并以产生最终的查询输出。
  • (InfluxDB Enterprise专用) remote_iterator节点表示在远程机器上完成的工作。

有关迭代器的更多信息,请参阅理解迭代器

cursor类型

EXPLAIN ANALYZE区分了3种游标类型。虽然游标类型具有相同的数据结构并且CPU和I/O成本相同,但每种游标类型都是为不同的原因构建并分离到最终输出中的。在调整语句时考虑以下游标类型

  • cursor_ref:为包含函数(如last()mean())的SELECT投影创建的引用游标。
  • cursor_aux:为简单的表达式投影创建的辅助游标(不是选择器或聚合)。例如,SELECT foo FROM mSELECT foo+bar FROM m,其中foobar是字段。
  • cursor_cond:为WHERE子句中引用的字段创建的条件游标。

有关游标的更多信息,请参阅理解游标

block类型

EXPLAIN ANALYZE将存储块类型分开,并报告解码的总块数及其在磁盘上的大小(以字节为单位)。以下块类型是受支持的

| float | 64位IEEE-754浮点数 | | integer | 64位有符号整数 | | unsigned | 64位无符号整数 | | boolean | 1位,LSB编码 | | string | UTF-8字符串 |

有关存储块更多信息,请参阅TSM文件

授权

注意:用户可以被授权对尚未存在的数据库进行权限设置。

grant_stmt = "GRANT" privilege [ on_clause ] to_clause .

示例

-- grant admin privileges
GRANT ALL TO "jdoe"

-- grant read access to a database
GRANT READ ON "mydb" TO "jdoe"

终止查询

停止当前正在运行的查询。

kill_query_statement = "KILL QUERY" query_id .

其中query_id是查询ID,在SHOW QUERIES输出中以qid显示。

InfluxDB企业集群:要终止集群上的查询,您需要指定查询ID(qid)和TCP主机(例如,myhost:8088),这些信息可在SHOW QUERIES输出中找到。

终止查询在“


#### Examples

```sql
-- kill query with qid of 36 on the local host
KILL QUERY 36
-- kill query on InfluxDB Enterprise cluster
KILL QUERY 53 ON "myhost:8088"

撤销

revoke_stmt = "REVOKE" privilege [ on_clause ] "FROM" user_name .

示例

-- revoke admin privileges from jdoe
REVOKE ALL PRIVILEGES FROM "jdoe"

-- revoke read privileges from jdoe on mydb
REVOKE READ ON "mydb" FROM "jdoe"

选择

select_stmt = "SELECT" fields from_clause [ into_clause ] [ where_clause ]
              [ group_by_clause ] [ order_by_clause ] [ limit_clause ]
              [ offset_clause ] [ slimit_clause ] [ soffset_clause ] [ timezone_clause ] .

示例

从所有以cpu开头的测量中选择,并在cpu_1h保留策略中的相同测量名称中

SELECT mean("value") INTO "cpu_1h".:MEASUREMENT FROM /cpu.*/

按带时区的天分组选择测量

SELECT mean("value") FROM "cpu" GROUP BY region, time(1d) fill(0) tz('America/Chicago')

显示基数

指的是用于估计或精确计算测量、系列、标签键、标签键值和字段键基数的一组命令。

SHOW CARDINALITY命令有两种变体:估计和精确。估计值使用草图计算,是所有基数大小的安全默认值。精确值直接来自TSM(时间结构合并树)数据,但对于高基数数据来说运行成本很高。除非需要,请使用估计值。

当在数据库上启用时间序列索引(TSI)时,才支持通过time进行筛选。

请参阅具体的SHOW CARDINALITY命令以获取详细信息

显示连续查询

show_continuous_queries_stmt = "SHOW CONTINUOUS QUERIES" .

示例

-- show all continuous queries
SHOW CONTINUOUS QUERIES

显示数据库

show_databases_stmt = "SHOW DATABASES" .

示例

-- show all databases
SHOW DATABASES

显示诊断

显示节点信息,例如构建信息、运行时间、主机名、服务器配置、内存使用和Go运行时诊断。

有关使用SHOW DIAGNOSTICS命令的更多信息,请参阅使用SHOW DIAGNOSTICS命令来监控InfluxDB

show_diagnostics_stmt = "SHOW DIAGNOSTICS"

显示字段键基数

除非使用ON <database>选项指定数据库,否则将精确估计或计算当前数据库中字段键集的基数。

注意:ON <database>FROM <sources>WITH KEY = <key>WHERE <condition>GROUP BY <dimensions>LIMIT/OFFSET子句是可选的。当使用这些查询子句时,查询将回退到精确计数。当启用时间序列索引(TSI)且time不在WHERE子句中时,才支持通过time进行筛选。

show_field_key_cardinality_stmt = "SHOW FIELD KEY CARDINALITY" [ on_clause ] [ from_clause ] [ where_clause ] [ group_by_clause ] [ limit_clause ] [ offset_clause ]

show_field_key_exact_cardinality_stmt = "SHOW FIELD KEY EXACT CARDINALITY" [ on_clause ] [ from_clause ] [ where_clause ] [ group_by_clause ] [ limit_clause ] [ offset_clause ]

示例

-- show estimated cardinality of the field key set of current database
SHOW FIELD KEY CARDINALITY
-- show exact cardinality on field key set of specified database
SHOW FIELD KEY EXACT CARDINALITY ON mydb

显示字段键

show_field_keys_stmt = "SHOW FIELD KEYS" [on_clause] [ from_clause ] .

示例

-- show field keys and field value data types from all measurements
SHOW FIELD KEYS

-- show field keys and field value data types from specified measurement
SHOW FIELD KEYS FROM "cpu"

显示授权

show_grants_stmt = "SHOW GRANTS FOR" user_name .

示例

-- show grants for jdoe
SHOW GRANTS FOR "jdoe"

显示测量基数

除非使用ON <database>选项指定数据库,否则将精确估计或计算当前数据库中测量集的基数。

注意:ON <database>FROM <sources>WITH KEY = <key>WHERE <condition>GROUP BY <dimensions>LIMIT/OFFSET子句是可选的。当使用这些查询子句时,查询将回退到精确计数。当启用TSI(时间序列索引)且time不在WHERE子句中时,才支持通过time进行筛选。

show_measurement_cardinality_stmt = "SHOW MEASUREMENT CARDINALITY" [ on_clause ] [ from_clause ] [ where_clause ] [ group_by_clause ] [ limit_clause ] [ offset_clause ]

show_measurement_exact_cardinality_stmt = "SHOW MEASUREMENT EXACT CARDINALITY" [ on_clause ] [ from_clause ] [ where_clause ] [ group_by_clause ] [ limit_clause ] [ offset_clause ]

示例

-- show estimated cardinality of measurement set on current database
SHOW MEASUREMENT CARDINALITY
-- show exact cardinality of measurement set on specified database
SHOW MEASUREMENT EXACT CARDINALITY ON mydb

显示测量值

show_measurements_stmt = "SHOW MEASUREMENTS" [on_clause] [ with_measurement_clause ] [ where_clause ] [ limit_clause ] [ offset_clause ] .

示例

-- show all measurements
SHOW MEASUREMENTS

-- show measurements where region tag = 'uswest' AND host tag = 'serverA'
SHOW MEASUREMENTS WHERE "region" = 'uswest' AND "host" = 'serverA'

-- show measurements that start with 'h2o'
SHOW MEASUREMENTS WITH MEASUREMENT =~ /h2o.*/

显示查询

show_queries_stmt = "SHOW QUERIES" .

示例

-- show all currently-running queries
SHOW QUERIES
--

显示保留策略

show_retention_policies_stmt = "SHOW RETENTION POLICIES" [on_clause] .

示例

-- show all retention policies on a database
SHOW RETENTION POLICIES ON "mydb"

显示系列

show_series_stmt = "SHOW SERIES" [on_clause] [ from_clause ] [ where_clause ] [ limit_clause ] [ offset_clause ] .

示例

SHOW SERIES FROM "telegraf"."autogen"."cpu" WHERE cpu = 'cpu8'

显示系列基数

除非使用ON <database>选项指定数据库,否则精确估计当前数据库中系列的基数。

系列基数是影响RAM需求的主要因素。更多信息,请参见

注意:ON <database>FROM <sources>WITH KEY = <key>WHERE <condition>GROUP BY <dimensions>LIMIT/OFFSET子句是可选的。当使用这些查询子句时,查询将回退到精确计数。在WHERE子句中不支持通过time进行过滤。

show_series_cardinality_stmt = "SHOW SERIES CARDINALITY" [ on_clause ] [ from_clause ] [ where_clause ] [ group_by_clause ] [ limit_clause ] [ offset_clause ]

show_series_exact_cardinality_stmt = "SHOW SERIES EXACT CARDINALITY" [ on_clause ] [ from_clause ] [ where_clause ] [ group_by_clause ] [ limit_clause ] [ offset_clause ]

示例

-- show estimated cardinality of the series on current database
SHOW SERIES CARDINALITY
-- show estimated cardinality of the series on specified database
SHOW SERIES CARDINALITY ON mydb
-- show exact series cardinality
SHOW SERIES EXACT CARDINALITY
-- show series cardinality of the series on specified database
SHOW SERIES EXACT CARDINALITY ON mydb

显示分片组

show_shard_groups_stmt = "SHOW SHARD GROUPS" .

示例

SHOW SHARD GROUPS

显示分片

show_shards_stmt = "SHOW SHARDS" .

示例

SHOW SHARDS

name: telegraf
id  database   retention_policy shard_group start_time           end_time             expiry_time          owners
--  --------   ---------------- ----------- ----------           --------             -----------          ------
16  telegraf   autogen          6           2020-10-19T00:00:00Z 2020-10-26T00:00:00Z 2020-10-26T00:00:00Z 6,7,8
17  telegraf   autogen          6           2020-10-19T00:00:00Z 2020-10-26T00:00:00Z 2020-10-26T00:00:00Z 9,4,5
21  telegraf   autogen          8           2020-10-26T00:00:00Z 2020-11-02T00:00:00Z 2020-11-02T00:00:00Z 8,9,4
22  telegraf   autogen          8           2020-10-26T00:00:00Z 2020-11-02T00:00:00Z 2020-11-02T00:00:00Z 5,6,7
26  telegraf   autogen          10          2020-11-02T00:00:00Z 2020-11-09T00:00:00Z 2020-11-09T00:00:00Z 9,4,5
27  telegraf   autogen          10          2020-11-02T00:00:00Z 2020-11-09T00:00:00Z 2020-11-09T00:00:00Z 6,7,8
31  telegraf   autogen          12          2020-11-09T00:00:00Z 2020-11-16T00:00:00Z 2020-11-16T00:00:00Z 6,7,8

SHOW SHARDS输出以下数据

  • id列:属于指定databaseretention policy的分片ID。
  • shard_group列:分片所属的组号。同一分片组中的分片具有相同的start_timeend_time。此间隔表示分片的活动时间,而expiry_time列显示分片组何时过期。如果保留策略持续时间设置为无限,则expiry_time下将不显示时间戳。
  • owners列:显示拥有分片的数据节点。拥有分片的节点数等于复制因子。在此示例中,复制因子为3,因此3个节点拥有每个分片。

显示统计信息

返回InfluxDB节点可用组件和可用(启用)组件的详细统计信息。

SHOW STATS返回的统计信息存储在内存中,当节点重新启动时重置为零,但SHOW STATS每10秒触发一次以填充_internal数据库。

SHOW STATS命令不列出索引内存使用情况 - 使用SHOW STATS FOR 'indexes'命令。

有关使用SHOW STATS命令的更多信息,请参阅使用SHOW STATS命令监控InfluxDB

show_stats_stmt = "SHOW STATS [ FOR '<component>' | 'indexes' ]"

示例

> show stats
name: runtime
-------------
Alloc   Frees   HeapAlloc       HeapIdle        HeapInUse       HeapObjects     HeapReleased    HeapSys         Lookups Mallocs NumGC   NumGoroutine    PauseTotalNs    Sys             TotalAlloc
4136056 6684537 4136056         34586624        5816320         49412           0               40402944        110     6733949 83      44              36083006        46692600        439945704

name: graphite
tags: proto=tcp
batches_tx      bytes_rx        connections_active      connections_handled     points_rx       points_tx
----------      --------        ------------------      -------------------     ---------       ---------
159             3999750         0                       1                       158110          158110

SHOW STATS FOR <component>

对于指定的组件(<component>),该命令返回可用统计信息。对于runtime组件,该命令使用Go运行时包返回InfluxDB系统内存使用的概述。

SHOW STATS FOR 'indexes'

返回所有索引内存使用的估计值。由于这是一个可能昂贵的操作,因此索引内存使用情况不与SHOW STATS一起报告。

显示订阅

show_subscriptions_stmt = "SHOW SUBSCRIPTIONS" .

示例

SHOW SUBSCRIPTIONS

显示标签键基数

除非使用ON <database>选项指定数据库,否则精确估计当前数据库上设置的标签键的基数。

注意:ON <database>FROM <sources>WITH KEY = <key>WHERE <condition>GROUP BY <dimensions>LIMIT/OFFSET子句是可选的。当使用这些查询子句时,查询将回退到精确计数。当启用TSI(时间序列索引)且time不在WHERE子句中时,才支持通过time进行筛选。

show_tag_key_cardinality_stmt = "SHOW TAG KEY CARDINALITY" [ on_clause ] [ from_clause ] [ where_clause ] [ group_by_clause ] [ limit_clause ] [ offset_clause ]

show_tag_key_exact_cardinality_stmt = "SHOW TAG KEY EXACT CARDINALITY" [ on_clause ] [ from_clause ] [ where_clause ] [ group_by_clause ] [ limit_clause ] [ offset_clause ]

示例

-- show estimated tag key cardinality
SHOW TAG KEY CARDINALITY
-- show exact tag key cardinality
SHOW TAG KEY EXACT CARDINALITY

显示标签键

show_tag_keys_stmt = "SHOW TAG KEYS" [on_clause] [ from_clause ] [ where_clause ]
                     [ limit_clause ] [ offset_clause ] .

示例

-- show all tag keys
SHOW TAG KEYS

-- show all tag keys from the cpu measurement
SHOW TAG KEYS FROM "cpu"

-- show all tag keys from the cpu measurement where the region key = 'uswest'
SHOW TAG KEYS FROM "cpu" WHERE "region" = 'uswest'

-- show all tag keys where the host key = 'serverA'
SHOW TAG KEYS WHERE "host" = 'serverA'

显示标签值

show_tag_values_stmt = "SHOW TAG VALUES" [on_clause] [ from_clause ] with_tag_clause [ where_clause ]
                       [ limit_clause ] [ offset_clause ] .

示例

-- show all tag values across all measurements for the region tag
SHOW TAG VALUES WITH KEY = "region"

-- show tag values from the cpu measurement for the region tag
SHOW TAG VALUES FROM "cpu" WITH KEY = "region"

-- show tag values across all measurements for all tag keys that do not include the letter c
SHOW TAG VALUES WITH KEY !~ /.*c.*/

-- show tag values from the cpu measurement for region & host tag keys where service = 'redis'
SHOW TAG VALUES FROM "cpu" WITH KEY IN ("region", "host") WHERE "service" = 'redis'

显示标签值基数

除非使用ON <database>选项指定数据库,否则精确估计指定标签键的标签键值的基数。

注意:ON <database>FROM <sources>WITH KEY = <key>WHERE <condition>GROUP BY <dimensions>LIMIT/OFFSET子句是可选的。当使用这些查询子句时,查询将回退到精确计数。仅当启用TSI(时间序列索引)时才支持通过time进行过滤。

show_tag_values_cardinality_stmt = "SHOW TAG VALUES CARDINALITY" [ on_clause ] [ from_clause ] [ where_clause ] [ group_by_clause ] [ limit_clause ] [ offset_clause ] with_key_clause

show_tag_values_exact_cardinality_stmt = "SHOW TAG VALUES EXACT CARDINALITY" [ on_clause ] [ from_clause ] [ where_clause ] [ group_by_clause ] [ limit_clause ] [ offset_clause ] with_key_clause

示例

-- show estimated tag key values cardinality for a specified tag key
SHOW TAG VALUES CARDINALITY WITH KEY = "myTagKey"
-- show estimated tag key values cardinality for a specified tag key
SHOW TAG VALUES CARDINALITY WITH KEY = "myTagKey"
-- show exact tag key values cardinality for a specified tag key
SHOW TAG VALUES EXACT CARDINALITY WITH KEY = "myTagKey"
-- show exact tag key values cardinality for a specified tag key
SHOW TAG VALUES EXACT CARDINALITY WITH KEY = "myTagKey"

显示用户

show_users_stmt = "SHOW USERS" .

示例

-- show all users
SHOW USERS

子句

from_clause     = "FROM" measurements .

group_by_clause = "GROUP BY" dimensions fill(fill_option).

into_clause     = "INTO" ( measurement | back_ref ).

limit_clause    = "LIMIT" int_lit .

offset_clause   = "OFFSET" int_lit .

slimit_clause   = "SLIMIT" int_lit .

soffset_clause  = "SOFFSET" int_lit .

timezone_clause = tz(string_lit) .

on_clause       = "ON" db_name .

order_by_clause = "ORDER BY" sort_fields .

to_clause       = "TO" user_name .

where_clause    = "WHERE" expr .

with_measurement_clause = "WITH MEASUREMENT" ( "=" measurement | "=~" regex_lit ) .

with_tag_clause = "WITH KEY" ( "=" tag_key | "!=" tag_key | "=~" regex_lit | "IN (" tag_keys ")"  ) .

表达式

binary_op        = "+" | "-" | "*" | "/" | "%" | "&" | "|" | "^" | "AND" |
                   "OR" | "=" | "!=" | "<>" | "<" | "<=" | ">" | ">=" .

expr             = unary_expr { binary_op unary_expr } .

unary_expr       = "(" expr ")" | var_ref | time_lit | string_lit | int_lit |
                   float_lit | bool_lit | duration_lit | regex_lit .

注释

使用InfluxQL语句的注释来描述您的查询。

  • 单行注释以两个短横线(--)开始,并在InfluxDB检测到行断点处结束。这种类型的注释不能跨越多行。
  • 多行注释以/*开始,以*/结束。这种类型的注释可以跨越多行。多行注释不支持嵌套的多行注释。

其他

alias            = "AS" identifier .

back_ref         = ( policy_name ".:MEASUREMENT" ) |
                   ( db_name "." [ policy_name ] ".:MEASUREMENT" ) .

db_name          = identifier .

dimension        = expr .

dimensions       = dimension { "," dimension } .

field_key        = identifier .

field            = expr [ alias ] .

fields           = field { "," field } .

fill_option      = "null" | "none" | "previous" | int_lit | float_lit | "linear" .

host             = string_lit .

measurement      = measurement_name |
                   ( policy_name "." measurement_name ) |
                   ( db_name "." [ policy_name ] "." measurement_name ) .

measurements     = measurement { "," measurement } .

measurement_name = identifier | regex_lit .

password         = string_lit .

policy_name      = identifier .

privilege        = "ALL" [ "PRIVILEGES" ] | "READ" | "WRITE" .

query_id         = int_lit .

query_name       = identifier .

retention_policy = identifier .

retention_policy_option      = retention_policy_duration |
                               retention_policy_replication |
                               retention_policy_shard_group_duration |
                               "DEFAULT" .

retention_policy_duration    = "DURATION" duration_lit .

retention_policy_replication = "REPLICATION" int_lit .

retention_policy_shard_group_duration = "SHARD DURATION" duration_lit .

retention_policy_name = "NAME" identifier .

series_id        = int_lit .

shard_id         = int_lit .

sort_field       = field_key [ ASC | DESC ] .

sort_fields      = sort_field { "," sort_field } .

subscription_name = identifier .

tag_key          = identifier .

tag_keys         = tag_key { "," tag_key } .

user_name        = identifier .

var_ref          = measurement .

这个页面有帮助吗?

感谢您的反馈!


Flux的未来

Flux将进入维护模式。您可以在不更改代码的情况下继续按当前方式使用它。

阅读更多

InfluxDB v3增强和InfluxDB Clustered现已一般可用

新功能,包括更快的查询性能和管理工具,推动了InfluxDB v3产品线的进步。InfluxDB Clustered现已一般可用。

InfluxDB v3性能和功能

InfluxDB v3产品线在查询性能方面取得了显著提升,并提供了新的管理工具。这些增强包括用于监控InfluxDB集群健康状态的运营仪表板、InfluxDB Cloud Dedicated中的单一登录(SSO)支持以及用于令牌和数据库的新管理API。

了解v3的新增强功能


InfluxDB Clustered一般可用

InfluxDB Clustered现已一般可用,并为您在自行管理的堆栈中提供了InfluxDB v3的力量。

与我们谈论InfluxDB Clustered