hey, i have some queries they become very slow (~70 seconds). here is one of this:
WITH diff AS (
SELECT
ts,
(
fields['Acct-Input-Octets'] - COALESCE(
LAG(fields['Acct-Input-Octets']) OVER (
PARTITION BY tags['Acct-Session-Id']
ORDER BY
ts ASC
),
0
)
) AS input_octets_diff,
(
fields['Acct-Output-Octets'] - COALESCE(
LAG(fields['Acct-Output-Octets']) OVER (
PARTITION BY tags['Acct-Session-Id']
ORDER BY
ts ASC
),
0
)
) AS output_octets_diff
FROM
doc.accounting
WHERE
tags['Acct-Session-Id'] IS NOT NULL
AND ts BETWEEN '2024-07-11T13:50:58.452Z' AND '2024-07-12T13:50:58.452Z'
AND tags['NAS-Identifier'] ~ '(AA:BB:CC:11:22:33|...|44:55:66:DD:EE:FF)'
AND tags['SSID'] ~ '(SSID1|SSID2)'
ORDER BY
tags['Acct-Session-Id'],
ts ASC
),
sum_window AS (
SELECT
date_bin('15 minutes' :: INTERVAL, ts, 0) as ts_15_min,
SUM(input_octets_diff) AS input_octets_15_min,
SUM(output_octets_diff) AS output_octets_15_min
FROM
diff
GROUP BY
ts_15_min
),
sum_window_15_min AS (
SELECT
ts_15_min,
SUM(input_octets_15_min) OVER(
ORDER BY
ts_15_min ROWS BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
) AS input_octets_15_min_cum,
SUM(output_octets_15_min) OVER(
ORDER BY
ts_15_min ROWS BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW
) AS output_octets_15_min_cum
FROM
sum_window
ORDER BY
ts_15_min
)
SELECT
ts_15_min as time,
input_octets_15_min_cum,
output_octets_15_min_cum,
input_octets_15_min_cum + output_octets_15_min_cum as total
FROM
sum_window_15_min;
as i can say, the problem seems to be the number of tags['NAS-Identifier']
that i have to check. in this example, i have tried it with regex, but also the same result seems to be if i use IN
or ANY
. how can i speed up my query with an large number NAS-Identifier
to check (in my current setup are ~230)
regards, volker.