Commit 35cb574a authored by Tom Lane's avatar Tom Lane

Suppress -Wimplicit-fallthrough warning in new LIMIT WITH TIES code.

The placement of the fall-through comment in this code appears not to
work to suppress the warning in recent gcc.  Move it to the bottom of
the case group, and add an assertion that we didn't get there through
some other code path.  Also improve wording of nearby comments.

Julien Rouhaud, comment hacking by me

Discussion: https://postgr.es/m/CAOBaU_aLdPGU5wCpaowNLF-Q8328iR7mj1yJAhMOVsdLwY+sdg@mail.gmail.com
parent 328c7099
...@@ -138,17 +138,18 @@ ExecLimit(PlanState *pstate) ...@@ -138,17 +138,18 @@ ExecLimit(PlanState *pstate)
/* /*
* Forwards scan, so check for stepping off end of window. At * Forwards scan, so check for stepping off end of window. At
* the end of the window, the behavior depends on whether WITH * the end of the window, the behavior depends on whether WITH
* TIES was specified: in that case, we need to change the * TIES was specified: if so, we need to change the state
* state machine to LIMIT_WINDOWTIES. If not (nothing was * machine to WINDOWEND_TIES, and fall through to the code for
* specified, or ONLY was) return NULL without advancing the * that case. If not (nothing was specified, or ONLY was)
* subplan or the position variable but change the state * return NULL without advancing the subplan or the position
* machine to record having done so * variable, but change the state machine to record having
* done so.
* *
* Once at the end, ideally, we can shut down parallel * Once at the end, ideally, we would shut down parallel
* resources but that would destroy the parallel context which * resources; but that would destroy the parallel context
* would be required for rescans. To do that, we need to find * which might be required for rescans. To do that, we'll
* a way to pass down more information about whether rescans * need to find a way to pass down more information about
* are possible. * whether rescans are possible.
*/ */
if (!node->noCount && if (!node->noCount &&
node->position - node->offset >= node->count) node->position - node->offset >= node->count)
...@@ -161,7 +162,7 @@ ExecLimit(PlanState *pstate) ...@@ -161,7 +162,7 @@ ExecLimit(PlanState *pstate)
else else
{ {
node->lstate = LIMIT_WINDOWEND_TIES; node->lstate = LIMIT_WINDOWEND_TIES;
/* fall-through */ /* we'll fall through to the next case */
} }
} }
else else
...@@ -177,8 +178,9 @@ ExecLimit(PlanState *pstate) ...@@ -177,8 +178,9 @@ ExecLimit(PlanState *pstate)
} }
/* /*
* Tuple at limit is needed for comparation in subsequent * If WITH TIES is active, and this is the last in-window
* execution to detect ties. * tuple, save it to be used in subsequent WINDOWEND_TIES
* processing.
*/ */
if (node->limitOption == LIMIT_OPTION_WITH_TIES && if (node->limitOption == LIMIT_OPTION_WITH_TIES &&
node->position - node->offset == node->count - 1) node->position - node->offset == node->count - 1)
...@@ -194,7 +196,7 @@ ExecLimit(PlanState *pstate) ...@@ -194,7 +196,7 @@ ExecLimit(PlanState *pstate)
{ {
/* /*
* Backwards scan, so check for stepping off start of window. * Backwards scan, so check for stepping off start of window.
* As above, change only state-machine status if so. * As above, only change state-machine status if so.
*/ */
if (node->position <= node->offset + 1) if (node->position <= node->offset + 1)
{ {
...@@ -213,6 +215,9 @@ ExecLimit(PlanState *pstate) ...@@ -213,6 +215,9 @@ ExecLimit(PlanState *pstate)
break; break;
} }
Assert(node->lstate == LIMIT_WINDOWEND_TIES);
/* FALL THRU */
case LIMIT_WINDOWEND_TIES: case LIMIT_WINDOWEND_TIES:
if (ScanDirectionIsForward(direction)) if (ScanDirectionIsForward(direction))
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment