TIP: Give the datamanager the debgug flag '-dbg query' to see what actually happens !
Lets first examine the following query:
Code: Select all
string strQuery =
"SELECT 'COUNT(_original.._value)' "
"FROM "
"'MyDatapoint.variables.*' REMOTE 'AME:' "
"WHERE "
"(_DPT =\\"peanutbutter\\") TIMERANGE(\\"2017.08.08 00:00:00\\",\\"2017.08.11 00:00:00\\",1,0)";When you now look at the debug messages from the datamanager then you'll see that it is intelligent enough to realize that there are no datapoints matching the WHERE clause. The query is fast and there are no results.
But now consider the following query:
Code: Select all
string strQuery =
"SELECT 'COUNT(_original.._value)' "
"FROM "
"'MyDatapoint.variables.*' REMOTE 'AME:' "
"WHERE "
"(_DPT =\\"peanutbutter\\") OR (_DPT =\\"chocolate\\") TIMERANGE(\\"2017.08.08 00:00:00\\",\\"2017.08.11 00:00:00\\",1,0)";* The Datamanager will first (through the value archives) collect all data matching the 'FROM' and the timerange
* It will then apply the WHERE and conclude that no dp element matched the WHERE
* And will eventually return an 'empty' result
What can we learn from this:
* Apparently: a simple WHERE is done before collecting data.
* A complex WHERE is done after collecting ALL the data !
Our partial solution : we've moved the selection of datapoints into the FROM statement. Our FROM statement is now huge and our WHERE is now gone. If we now have 14 dp elements that match our filter, then our FROM mentions 14 dp elements and we see that the Datamanager is collecting data from exactly 14 dp elements.
Hope this helps and explains why your queries sometimes take a long time
Share the fun
Frenk Mulder