TQL

The TQL keyword executes TQL language in SQL. The TQL is Time-Series Query Language, which is an extension for Prometheus’s PromQL in GreptimeDB.

EVAL

Syntax

sql

  1. TQL [EVAL | EVALUATE] (start, end, step) expr

The start, end and step are the query parameters just like Prometheus Query API:

  • start: <rfc3339 | unix_timestamp>: Start timestamp, inclusive.
  • end: <rfc3339 | unix_timestamp>: End timestamp, inclusive.
  • step: <duration | float>: Query resolution step width in duration format or float number of seconds.

The expr is the TQL expression query string.

Examples

Return the per-second rate for all time series with the http_requests_total metric name, as measured over the last 5 minutes:

sql

  1. TQL eval (1677057993, 1677058993, '1m') rate(prometheus_http_requests_total{job="prometheus"}[5m]);

will get a result just like other normal SQL queries.

EXPLAIN

EXPLAIN displays both the logical plan and execution plan for a given PromQL query. The syntax is as follows:

  1. TQL EXPLAIN expr;

For example, to explain the PromQL sum by (instance) (rate(node_disk_written_bytes_total[2m])) > 50, we can use

  1. TQL EXPLAIN sum by (instance) (rate(node_disk_written_bytes_total[2m])) > 50;

Notice that since the given query won’t be actually executed, the triple (start, end, step) is not necessary. But you can still provide it like in TQL EVAL:

  1. TQL EXPLAIN (0, 100, '10s') sum by (instance) (rate(node_disk_written_bytes_total[2m])) > 50;

The result should be like the following:

txt

  1. +---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2. | plan_type | plan |
  3. +---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  4. | logical_plan | Sort: node_disk_written_bytes_total.instance ASC NULLS LAST, node_disk_written_bytes_total.ts ASC NULLS LAST
  5. Filter: SUM(prom_rate(ts_range,field,ts)) > Float64(50)
  6. Aggregate: groupBy=[[node_disk_written_bytes_total.instance, node_disk_written_bytes_total.ts]], aggr=[[SUM(prom_rate(ts_range,field,ts))]]
  7. Projection: node_disk_written_bytes_total.ts, prom_rate(ts_range, field, node_disk_written_bytes_total.ts) AS prom_rate(ts_range,field,ts), node_disk_written_bytes_total.instance
  8. Filter: prom_rate(ts_range, field, node_disk_written_bytes_total.ts) IS NOT NULL
  9. Projection: node_disk_written_bytes_total.ts, node_disk_written_bytes_total.instance, field, ts_range
  10. PromRangeManipulate: req range=[0..0], interval=[300000], eval range=[120000], time index=[ts], values=["field"]
  11. PromSeriesNormalize: offset=[0], time index=[ts], filter NaN: [true]
  12. PromSeriesDivide: tags=["instance"]
  13. Sort: node_disk_written_bytes_total.instance DESC NULLS LAST, node_disk_written_bytes_total.ts DESC NULLS LAST
  14. TableScan: node_disk_written_bytes_total projection=[ts, instance, field], partial_filters=[ts >= TimestampMillisecond(-420000, None), ts <= TimestampMillisecond(300000, None)] |
  15. | physical_plan | SortPreservingMergeExec: [instance@0 ASC NULLS LAST,ts@1 ASC NULLS LAST]
  16. SortExec: expr=[instance@0 ASC NULLS LAST,ts@1 ASC NULLS LAST]
  17. CoalesceBatchesExec: target_batch_size=8192
  18. FilterExec: SUM(prom_rate(ts_range,field,ts))@2 > 50
  19. AggregateExec: mode=FinalPartitioned, gby=[instance@0 as instance, ts@1 as ts], aggr=[SUM(prom_rate(ts_range,field,ts))]
  20. CoalesceBatchesExec: target_batch_size=8192
  21. RepartitionExec: partitioning=Hash([Column { name: "instance", index: 0 }, Column { name: "ts", index: 1 }], 32), input_partitions=32
  22. AggregateExec: mode=Partial, gby=[instance@2 as instance, ts@0 as ts], aggr=[SUM(prom_rate(ts_range,field,ts))]
  23. ProjectionExec: expr=[ts@0 as ts, prom_rate(ts_range@3, field@2, ts@0) as prom_rate(ts_range,field,ts), instance@1 as instance]
  24. CoalesceBatchesExec: target_batch_size=8192
  25. FilterExec: prom_rate(ts_range@3, field@2, ts@0) IS NOT NULL
  26. ProjectionExec: expr=[ts@0 as ts, instance@1 as instance, field@2 as field, ts_range@3 as ts_range]
  27. PromInstantManipulateExec: req range=[0..0], interval=[300000], eval range=[120000], time index=[ts]
  28. PromSeriesNormalizeExec: offset=[0], time index=[ts], filter NaN: [true]
  29. PromSeriesDivideExec: tags=["instance"]
  30. RepartitionExec: partitioning=RoundRobinBatch(32), input_partitions=1
  31. ExecutionPlan(PlaceHolder)
  32. |
  33. +---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

ANALYZE

TQL also supports ANALYZE keyword to analyze the given PromQL query’s execution. The syntax is as follows:

  1. TQL ANALYZE (start, end, step) expr;

For example:

  1. TQL ANALYZE (0, 10, '5s') test;

will get a result like

  1. +-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  2. | plan_type | plan |
  3. +-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  4. | Plan with Metrics | CoalescePartitionsExec, metrics=[output_rows=0, elapsed_compute=14.99µs]
  5. PromInstantManipulateExec: range=[0..10000], lookback=[300000], interval=[5000], time index=[j], metrics=[output_rows=0, elapsed_compute=1.08µs]
  6. PromSeriesNormalizeExec: offset=[0], time index=[j], filter NaN: [false], metrics=[output_rows=0, elapsed_compute=1.11µs]
  7. PromSeriesDivideExec: tags=["k"], metrics=[output_rows=0, elapsed_compute=1.3µs]
  8. RepartitionExec: partitioning=RoundRobinBatch(32), input_partitions=32, metrics=[send_time=32ns, repart_time=32ns, fetch_time=11.578016ms]
  9. RepartitionExec: partitioning=RoundRobinBatch(32), input_partitions=1, metrics=[send_time=1ns, repart_time=1ns, fetch_time=21.07µs]
  10. ExecutionPlan(PlaceHolder), metrics=[]
  11. |
  12. +-------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+