InfluxQL and Flux
InfluxQL and Flux are both evaluated inside the InfluxDB wire, over an in-memory copy of the data. Neither builds a LogicalPlan or calls QueryEngine for reads. Parameters, statement lists, the SELECT grammar, function lists, storage records and tests are documented in InfluxDB: implementation reference; this page describes how each language is translated and where the two differ.
Translation path
(source: src/protocol/influxdb/mod.rs, handle_query, run_influxql, split_influxql_statements, bind_influxql_params, execute_select, execute_flux; src/protocol/influxdb/influxql.rs, parse, execute, parse_show, execute_show, parse_delete)
InfluxQL
-
Front end. The request's
qis split on;,$nameparameters are substituted as text, and each statement's first word must be a known InfluxQL keyword or the whole request fails with 400 (source:src/protocol/influxdb/mod.rs,split_influxql_statements,bind_influxql_params,run_influxql). -
Parser.
influxql::parsetokenizes and builds aSelectvalue: projections,FROMmeasurement or subquery, aWHEREcondition tree,GROUP BY time(...)and tags,fill,ORDER BY time,LIMIT/OFFSET/SLIMIT/SOFFSET(source:src/protocol/influxdb/influxql.rs,parse,tokenize). -
Evaluator.
influxql::executeextracts time bounds from the condition, scans the measurement'sVec<Point>, groups by series, buckets by time, applies aggregates, selectors, transformations and fill, and formats series JSON (source:src/protocol/influxdb/influxql.rs,execute,time_bounds,eval_cond,execute_series,aggregate_series,transform,apply_fill). -
Fallback. A
SELECTthat the parser rejects is passed toexecute_select, an older handler that matches substrings of the statement (source:src/protocol/influxdb/mod.rs,execute_select). Not verified: no test exercises the fallback handler, so which statements it answers, and how, is not established. -
Writes from queries.
SELECT ... INTOevaluates the query, converts the rows to points withexecute_into_points, and writes and persists them like line-protocol points (source:src/protocol/influxdb/mod.rs,execute_select_into;src/protocol/influxdb/influxql.rs,execute_into_points).
Supported functions: aggregates and selectors count, sum, mean, median, min, max, first, last, spread, stddev, percentile, mode, distinct, top, bottom; transformations derivative, non_negative_derivative, difference, non_negative_difference, cumulative_sum, moving_average, abs, ceil, floor, round. Other names return unsupported function <name>, and field::type casts return type casts unsupported (source: src/protocol/influxdb/influxql.rs, AGGREGATES, TRANSFORMS, parse_proj_atom).
Statements that are accepted but do nothing: EXPLAIN, GRANT, REVOKE, SET, KILL, ALTER other than retention policies, and other CREATE/DROP forms. Retention policies are stored but never expire data (source: src/protocol/influxdb/mod.rs, run_influxql, retention_policy_stmt).
Tested by grafana_time_bucketed_mean_by_tag, fill_none_drops_empty_buckets_and_where_or, raw_select_where_field_limit_desc_and_rfc3339, selector_reports_point_time_and_derivative and unsupported_shapes_are_errors_not_wrong_answers in src/protocol/influxdb/influxql.rs, by binds_strings_numbers_and_skips_quoted_text in src/protocol/influxdb/mod.rs, and by the InfluxDB 1.8 differential recorded in the proof pack (source: reference, section 10).
Flux
There is no Flux parser. execute_flux searches the query text for:
| Fragment | Effect |
|---|---|
bucket: |
Database name |
range(start:, stop:) |
Time bounds |
filter(...) bodies |
Split on and or && into r._measurement == "x", r._field == "y" and r.<tag> == "v"
|
aggregateWindow(every:, fn:) |
Bucketing; fn is mean, sum, count, min, max, first or last, and any other value is treated as mean
|
Every other Flux function in the text is ignored, so map, pivot, group, join, yield names and or in filters change nothing and raise no error. Output is annotated CSV with columns result, table, _time, _measurement, _field, _value; aggregation uses numeric values only (source: src/protocol/influxdb/mod.rs, execute_flux, parse_flux_filter, parse_flux_range, parse_flux_aggregate_window, parse_flux_duration).
Not verified: no test of the Flux path was found.
Storage and reachability from SQL
Points are kept in memory and written as one key-value record per point under __influx__:pt:; databases and retention policies under __influx__:db: and __influx__:rp: (source: src/protocol/influxdb/mod.rs, PT_PREFIX, DB_PREFIX, RP_PREFIX, point_entry). These are not SQL tables, so InfluxDB data is not readable over the SQL wires. HTTP Studio's protocol: influxdb returns a hint to use the native port instead of running the query (source: src/protocol/http/routes.rs, execute_query_for_studio).