Description
Issue #3219 points out that we were incorrectly feeding back the continuation in RecordQueryFirstOrDefaultPlan
s to the inner continuation when resuming it. That meant that we were not resuming the continuation from the right place. However, in reality, there are three states that the cursor needs to consider:
- The inner cursor returned a result. In this case, the first value is returned
- The inner cursor was empty. In this case, the default value is returned
- The inner cursor hit an out of band limit. In this case, we are unable to determine if the underlying cursor is empty or not
In both of the first two cases, because we've returned a result, we no longer need to record any state about the inner cursor, and we should just return a continuation that amounts to "we are done after this". In the third case, we should provide the inner cursor its previous continuation and continue on. That implies a continuation like:
message ForOrDefaultContinuation {
optional bytes innerContinuation = 1;
optional bool returnedValue = 2;
}
Technically, we could get by with something like just the inner continuation, and if the field is empty, then that means that we have already exhausted the continuation, but one would have to be careful around not returning an empty array.
Note: this was originally the scope of #3219. However, that issue has been repurposed to fixing the fact that the continuation wasn't being properly handled at all by the plan, which meant it was always resuming from the wrong place. This is to fix the other issue identified in a follow up.