@@ -138,17 +138,18 @@ ExecLimit(PlanState *pstate)
138
138
/*
139
139
* Forwards scan, so check for stepping off end of window. At
140
140
* the end of the window, the behavior depends on whether WITH
141
- * TIES was specified: in that case, we need to change the
142
- * state machine to LIMIT_WINDOWTIES. If not (nothing was
143
- * specified, or ONLY was) return NULL without advancing the
144
- * subplan or the position variable but change the state
145
- * machine to record having done so
141
+ * TIES was specified: if so, we need to change the state
142
+ * machine to WINDOWEND_TIES, and fall through to the code for
143
+ * that case. If not (nothing was specified, or ONLY was)
144
+ * return NULL without advancing the subplan or the position
145
+ * variable, but change the state machine to record having
146
+ * done so.
146
147
*
147
- * Once at the end, ideally, we can shut down parallel
148
- * resources but that would destroy the parallel context which
149
- * would be required for rescans. To do that, we need to find
150
- * a way to pass down more information about whether rescans
151
- * are possible.
148
+ * Once at the end, ideally, we would shut down parallel
149
+ * resources; but that would destroy the parallel context
150
+ * which might be required for rescans. To do that, we'll
151
+ * need to find a way to pass down more information about
152
+ * whether rescans are possible.
152
153
*/
153
154
if (!node -> noCount &&
154
155
node -> position - node -> offset >= node -> count )
@@ -161,7 +162,7 @@ ExecLimit(PlanState *pstate)
161
162
else
162
163
{
163
164
node -> lstate = LIMIT_WINDOWEND_TIES ;
164
- /* fall- through */
165
+ /* we'll fall through to the next case */
165
166
}
166
167
}
167
168
else
@@ -177,8 +178,9 @@ ExecLimit(PlanState *pstate)
177
178
}
178
179
179
180
/*
180
- * Tuple at limit is needed for comparation in subsequent
181
- * execution to detect ties.
181
+ * If WITH TIES is active, and this is the last in-window
182
+ * tuple, save it to be used in subsequent WINDOWEND_TIES
183
+ * processing.
182
184
*/
183
185
if (node -> limitOption == LIMIT_OPTION_WITH_TIES &&
184
186
node -> position - node -> offset == node -> count - 1 )
@@ -194,7 +196,7 @@ ExecLimit(PlanState *pstate)
194
196
{
195
197
/*
196
198
* Backwards scan, so check for stepping off start of window.
197
- * As above, change only state-machine status if so.
199
+ * As above, only change state-machine status if so.
198
200
*/
199
201
if (node -> position <= node -> offset + 1 )
200
202
{
@@ -213,6 +215,9 @@ ExecLimit(PlanState *pstate)
213
215
break ;
214
216
}
215
217
218
+ Assert (node -> lstate == LIMIT_WINDOWEND_TIES );
219
+ /* FALL THRU */
220
+
216
221
case LIMIT_WINDOWEND_TIES :
217
222
if (ScanDirectionIsForward (direction ))
218
223
{
0 commit comments