aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeMaterial.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-12-27 17:39:00 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-12-27 17:39:00 +0000
commit38e9348282e9d078487147ba8a85aebec54e3a08 (patch)
treea893e05cad02c5e42d16aa1533fb5aa8d4cc5547 /src/backend/executor/nodeMaterial.c
parentc8b69ed6a892d7db5998e99b1fdae4b30d75a807 (diff)
downloadpostgresql-38e9348282e9d078487147ba8a85aebec54e3a08.tar.gz
postgresql-38e9348282e9d078487147ba8a85aebec54e3a08.zip
Make a couple of small changes to the tuplestore API, for the benefit of the
upcoming window-functions patch. First, tuplestore_trim is now an exported function that must be explicitly invoked by callers at appropriate times, rather than something that tuplestore tries to do behind the scenes. Second, a read pointer that is marked as allowing backward scan no longer prevents truncation. This means that a read pointer marked as having BACKWARD but not REWIND capability can only safely read backwards as far as the oldest other read pointer. (The expected use pattern for this involves having another read pointer that serves as the truncation fencepost.)
Diffstat (limited to 'src/backend/executor/nodeMaterial.c')
-rw-r--r--src/backend/executor/nodeMaterial.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/backend/executor/nodeMaterial.c b/src/backend/executor/nodeMaterial.c
index 494560d0f46..baf8a99717e 100644
--- a/src/backend/executor/nodeMaterial.c
+++ b/src/backend/executor/nodeMaterial.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/executor/nodeMaterial.c,v 1.63 2008/10/01 19:51:49 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/executor/nodeMaterial.c,v 1.64 2008/12/27 17:39:00 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -66,11 +66,11 @@ ExecMaterial(MaterialState *node)
* Allocate a second read pointer to serve as the mark.
* We know it must have index 1, so needn't store that.
*/
- int ptrn;
+ int ptrno;
- ptrn = tuplestore_alloc_read_pointer(tuplestorestate,
- node->eflags);
- Assert(ptrn == 1);
+ ptrno = tuplestore_alloc_read_pointer(tuplestorestate,
+ node->eflags);
+ Assert(ptrno == 1);
}
node->tuplestorestate = tuplestorestate;
}
@@ -182,6 +182,16 @@ ExecInitMaterial(Material *node, EState *estate, int eflags)
EXEC_FLAG_BACKWARD |
EXEC_FLAG_MARK));
+ /*
+ * Tuplestore's interpretation of the flag bits is subtly different from
+ * the general executor meaning: it doesn't think BACKWARD necessarily
+ * means "backwards all the way to start". If told to support BACKWARD we
+ * must include REWIND in the tuplestore eflags, else tuplestore_trim
+ * might throw away too much.
+ */
+ if (eflags & EXEC_FLAG_BACKWARD)
+ matstate->eflags |= EXEC_FLAG_REWIND;
+
matstate->eof_underlying = false;
matstate->tuplestorestate = NULL;
@@ -278,6 +288,11 @@ ExecMaterialMarkPos(MaterialState *node)
* copy the active read pointer to the mark.
*/
tuplestore_copy_read_pointer(node->tuplestorestate, 0, 1);
+
+ /*
+ * since we may have advanced the mark, try to truncate the tuplestore.
+ */
+ tuplestore_trim(node->tuplestorestate);
}
/* ----------------------------------------------------------------