Hi I have Document A as-
{
"_id": "TimeSlots",
"timeSlots": [
{
"startTime": "00:00:00"
"endTime": "01:00:00",
},
{
"startTime": "01:00:00"
"endTime": "02:00:00",
},
{
"startTime": "02:00:00"
"endTime": "03:00:00",
},
{
"startTime": "03:00:00"
"endTime": "04:00:00",
}............,
{
"startTime": "23:00:00"
"endTime": "23:59:59",
}
] }
And Document B As -
{
"_id": "User::33243"
"userID": 33243,
"type": "User"
"userStatuses": [
{
"status": "ONLINE",
"statusChangedDate": "2017-07-20T08:20:00Z",
},
{
"status": "OFFLINE",
"statusChangedDate": "2017-07-20T09:21:00Z",
},
{
"status": "ONLINE",
"statusChangedDate": "2017-07-20T16:30:00Z",
},
{
"status": "OFFLINE",
"statusChangedDate": "2017-07-20T09:21:00Z",
}
]
}
What I’m trying to do is, to retrieve a list of all the timeslots having a corresponding count of the users Online at a particular day.
I designed the following query but it’s too slow and taking approx 2-3 minutes in execution.
Select TS.startTime || ' - ' || TS.endTime as Duration, Count(U.userID) as Users_Online
From example U
Unnest U.userStatuses S
Join example T on Keys 'TimeSlots'
Unnest T.timeSlots TS
Where U.type = 'User'
And T.type = 'TimeSlots'
And DATE_FORMAT_STR(S.statusChangedDate, '1111-11-11') = '2017-07-20'
And (DATE_FORMAT_STR(S.statusChangedDate, '01:01:01') >= TS.startTime
And DATE_FORMAT_STR(S.statusChangedDate, '01:01:01') < TS.endTime)
And S.status = 'ONLINE'
Group by TS.startTime, TS.endTime
Order by TS.startTime;
Can anyone suggest me how to create an index for this query so that its execution speed improves?
Thanks,
Krishan