2

1 分以上で結果を返す 1 つの influxSQL クエリを実行しています。クエリ:

select SUM(call_duration) as total_duration,Count(Distinct(recipient_id)) as total_recipients from xyz where target_id = '1';

次のような個別のクエリ

select Count(Distinct(recipient_id)) as total_recipients from xyz where target_id = '1';

select SUM(call_duration) as total_duration from xyz where target_id = '1';

また、結果が返されるまでに 1 分以上かかります。

while クエリ

select MAX(call_duration), MIN(call_duration) from xyz where target_id = '1';

3 ~ 4 秒などの秒単位で、非常に高速に結果を返します。

table(measurements) xyz が非常に大きいです。この where 条件に一致するレコードは 1,000 万件以上あります。call_duration と recipient_id はフィールドであり、target_id はタグです

MIN 関数と MAX 関数は非常に高速に結果を返しますが、SUM に時間がかかるのはなぜでしょうか?

InfluxDB バージョン: 1.7.4 マシン構成 - AWS EC2 - t2.medium (4 GB RAM)

構成ファイル:

[meta]
dir = "/var/lib/influxdb/meta"
[data]
dir = "/var/lib/influxdb/data"
wal-dir = "/var/lib/influxdb/wal"
series-id-set-cache-size = 100
[coordinator]
[retention]
[shard-precreation]
[monitor]
[http]
enabled = true
auth-enabled = true
log-enabled = true
access-log-path = "/var/log/influxdb/http_access.log"
write-tracing = false
max-body-size = 0
max-concurrent-write-limit = 0
[logging]
[subscriber]
[[graphite]]
[[collectd]]
[[opentsdb]]
[[udp]]
[continuous_queries]
[tls]

結果は5〜6秒で返ってくるはずだと思います

EXPLAIN select MIN(call_duration) from xyz where target_id='1';
QUERY PLAN
----------
EXPRESSION: min(call_duration::float)
NUMBER OF SHARDS: 21
NUMBER OF SERIES: 85134
CACHED VALUES: 0
NUMBER OF FILES: 24642
NUMBER OF BLOCKS: 31608
SIZE OF BLOCKS: 65520278

EXPLAIN select MAX(call_duration) from xyz where target_id='1';
QUERY PLAN
----------
EXPRESSION: max(call_duration::float)
NUMBER OF SHARDS: 21
NUMBER OF SERIES: 85134
CACHED VALUES: 0
NUMBER OF FILES: 24642
NUMBER OF BLOCKS: 31608
SIZE OF BLOCKS: 65520278

EXPLAIN select SUM(call_duration) as total_call_duration from xyz where target_id='1';
QUERY PLAN
----------
EXPRESSION: sum(call_duration::float)
NUMBER OF SHARDS: 21
NUMBER OF SERIES: 85134
CACHED VALUES: 0
NUMBER OF FILES: 24642
NUMBER OF BLOCKS: 31608
SIZE OF BLOCKS: 65520278

EXPLAIN select Count(Distinct(recipient_id)) as total_recipients from xyz where target_id='1';
QUERY PLAN
----------
EXPRESSION: recipient_id::integer
NUMBER OF SHARDS: 21
NUMBER OF SERIES: 85134
CACHED VALUES: 0
NUMBER OF FILES: 24642
NUMBER OF BLOCKS: 31608
SIZE OF BLOCKS: 82448255
4

0 に答える 0