Long running distinct queries

When using Grafana and having a lot of time-series data, it might take a while until the dropdown menu appears (up to a time when it does not work at all anymore).

Problem

In version before 0.9.6, the index was only optimized to fetch distinct values, but not based on the asset_id: **CREATE** **INDEX** **ON** processValueTable **(**valuename**);**

When using the 0.9.4 command from factoryinsight to fetch the distinct valuenames for a specific asset, the resulting query was not optimized EXPLAIN SELECT DISTINCT(valuename) FROM processvaluetable WHERE asset_id=2;

Untitled

Solution

Two steps:

1. Create Index

Execute:

CREATE INDEX ON processvaluetable(valuename, asset_id) WITH (timescaledb.transaction_per_chunk);

See also

Executing SQL commands in the United Manufacturing Hub?

Untitled

2. use better query

Additionally, roll back the factoryinsight Deployment back to v0.9.4 as the optimized command using CTE from #1193 and v0.9.5 is taking longer, than the original command from v0.9.4

CTE version:

Untitled

Naive distinct call:

Untitled

Last modified February 17, 2023: update (#208) (ea731fc)