-
Notifications
You must be signed in to change notification settings - Fork 31
Description
This is a question:
I use queries in mysql to fetch data, and i would like to reference the datapoint via alias.
My query looks like this:
SELECT iobroker.ts_number.ts as time, iobroker.ts_number.val as Netz FROM iobroker.ts_number WHERE iobroker.ts_number.id = (SELECT iobroker.datapoints.id from iobroker.datapoints WHERE iobroker.datapoints.name = "power") AND iobroker.ts_number.ts >= 1739401200000 AND iobroker.ts_number.ts <= 1739404800000 ;
All out of sudden this kind of query is not fast any more, it needs 40 sec.
Maybe the reason is that i have added new datapoints with lots of data...
The reason for using so much time is the query
(SELECT iobroker.datapoints.id from iobroker.datapoints WHERE iobroker.datapoints.name = "power")
within the query, which should select the correct datapoint-id. When i did introduce this kind of query in query i was told that the optimiser from mysql would fetch the id once and then process the query with the correct number.
What i know is that when i replace the query with the fix number then the respond time is 4 milliseconds.
I would like to try to add an additional index to the table datapoints for testing... i would like to add an index on name.
Would this be possible or would it have no effect.... or would it crash the system ?