cte-rescan.patch

text/x-patch

Filename: cte-rescan.patch
Type: text/x-patch
Part: 0
Message: Bogus rescan logic in ExecReScanCteScan

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: unified
File+
src/backend/executor/nodeCtescan.c 0 0
diff --git a/src/backend/executor/nodeCtescan.c b/src/backend/executor/nodeCtescan.c
index 7ab15ac63e1020dd00b3ef27950615dc108b795b..d45352896b09b7580f1518450366d53cbcfdbc1e 100644
*** a/src/backend/executor/nodeCtescan.c
--- b/src/backend/executor/nodeCtescan.c
*************** ExecReScanCteScan(CteScanState *node)
*** 312,337 ****
  
  	ExecScanReScan(&node->ss);
  
! 	if (node->leader == node)
  	{
! 		/*
! 		 * The leader is responsible for clearing the tuplestore if a new scan
! 		 * of the underlying CTE is required.
! 		 */
! 		if (node->cteplanstate->chgParam != NULL)
! 		{
! 			tuplestore_clear(tuplestorestate);
! 			node->eof_cte = false;
! 		}
! 		else
! 		{
! 			tuplestore_select_read_pointer(tuplestorestate, node->readptr);
! 			tuplestore_rescan(tuplestorestate);
! 		}
  	}
  	else
  	{
! 		/* Not leader, so just rewind my own pointer */
  		tuplestore_select_read_pointer(tuplestorestate, node->readptr);
  		tuplestore_rescan(tuplestorestate);
  	}
--- 312,333 ----
  
  	ExecScanReScan(&node->ss);
  
! 	/*
! 	 * Clear the tuplestore if a new scan of the underlying CTE is required.
! 	 * This implicitly resets all the tuplestore's read pointers.  Note that
! 	 * multiple CTE nodes might redundantly clear the tuplestore; that's OK,
! 	 * and not unduly expensive.  We'll stop taking this path as soon as
! 	 * somebody has attempted to read something from the underlying CTE
! 	 * (thereby causing its chgParam to be cleared).
! 	 */
! 	if (node->leader->cteplanstate->chgParam != NULL)
  	{
! 		tuplestore_clear(tuplestorestate);
! 		node->leader->eof_cte = false;
  	}
  	else
  	{
! 		/* Else, just rewind my own pointer */
  		tuplestore_select_read_pointer(tuplestorestate, node->readptr);
  		tuplestore_rescan(tuplestorestate);
  	}