To dIagnose these problems run the outer search on its own and the inner search on its own. You are using join, which is not necessary and may be the issue depending on your data size. You don't need the table commands all the time and you seem to be duplicating your time parsing (time and _time). Not sure you need reverse either - in the join, you are reversing to get the first timestamp, which in practice without the reverse would be the oldest _time, so you could just to earliest(timestamp) instead without reverse.
... View more