Slackbot
09/13/2023, 5:44 PMBen Krug
09/13/2023, 6:06 PMShithanshu Mishra
09/13/2023, 6:42 PMselect t.device_category, t.status, count(*) from
(select latest(device_category), latest(status), latest(device_id) from metric_table group by device_id) as temp_table t
group by t.device_category, t.status;
But the concern is that the complete table is probably scanned to fetch the latest record (pardon me if I am wrong)
Is there any way I can take advantage of something like a roll-up or something like a materialized view and still store all the events?Sergio Ferragut
09/13/2023, 7:07 PMselect t.device_category, t.status, count(*) from
(select device_category, device_id, latest(status)
from metric_table
WHERE __time > CURRENT_TIMESTAMP - INTERVAL '1' DAY
group by 1,2) as temp_table t
group by t.device_category, t.status;
You are correct, that without the time filter it would scan the whole table, so you would want to filter it on time, but perhaps you can use some timeframe that is safe: the max gap between events . If you have devices that do not report on a regular basis, you may need to inject an event with some frequency (daily for example) with the most recent value for that device into the stream, in order to keep the __time condition timeframe small and therefore consistent query performance.Shithanshu Mishra
09/14/2023, 5:12 AMSergio Ferragut
09/14/2023, 3:49 PMIf you have devices that do not report on a regular basis, you may need to inject an event with some frequency (daily for example) with the most recent value for that device into the stream,
It would mean that you add another 365 data points for devices with lower frequency than once a day, the event would have the most recent value. So if your max timeframe for the query is 1 day, it will always find a value.Shithanshu Mishra
09/15/2023, 5:14 AM