I have a simple table
desc house.solar;
+————-+————-+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+————-+————-+——+—–+———+——-+
| ts | datetime | YES | | NULL | |
| measurement | varchar(15) | YES | | NULL | |
| unit | varchar(10) | YES | | NULL | |
| value | float | YES | | NULL | |
+————-+————-+——+—–+———+——-+
against which I execute the following query
select hour(ts),avg(value) from solar where month(ts)=4 and measurement = 'DP1' and year(ts)=2023 group by hour(ts);
Sometimes the query takes a long time to execute.
I do this both from a C++/Qt 6.6.2 app and via the linux mysql command. Sometimes the query runs in “zero” time and then after a few repetitions (with different years, etc) it takes a couple of seconds. A a result the app sometimes is OK then change a parameter and it times out. I don’t think I am asking a lot of the database but… any pointers as to performance issues with the query? Next any pointers as to how to diagnose the database performance?
TIA