mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Add infrastructure to support EphemeralNamedRelation references.
A QueryEnvironment concept is added, which allows new types of objects to be passed into queries from parsing on through execution. At this point, the only thing implemented is a collection of EphemeralNamedRelation objects -- relations which can be referenced by name in queries, but do not exist in the catalogs. The only type of ENR implemented is NamedTuplestore, but provision is made to add more types fairly easily. An ENR can carry its own TupleDesc or reference a relation in the catalogs by relid. Although these features can be used without SPI, convenience functions are added to SPI so that ENRs can easily be used by code run through SPI. The initial use of all this is going to be transition tables in AFTER triggers, but that will be added to each PL as a separate commit. An incidental effect of this patch is to produce a more informative error message if an attempt is made to modify the contents of a CTE from a referencing DML statement. No tests previously covered that possibility, so one is added. Kevin Grittner and Thomas Munro Reviewed by Heikki Linnakangas, David Fetter, and Thomas Munro with valuable comments and suggestions from many others
This commit is contained in:
@@ -109,6 +109,7 @@ struct Tuplestorestate
|
||||
bool truncated; /* tuplestore_trim has removed tuples? */
|
||||
int64 availMem; /* remaining memory available, in bytes */
|
||||
int64 allowedMem; /* total memory allowed, in bytes */
|
||||
int64 tuples; /* number of tuples added */
|
||||
BufFile *myfile; /* underlying file, or NULL if none */
|
||||
MemoryContext context; /* memory context for holding tuples */
|
||||
ResourceOwner resowner; /* resowner for holding temp files */
|
||||
@@ -267,6 +268,7 @@ tuplestore_begin_common(int eflags, bool interXact, int maxKBytes)
|
||||
|
||||
state->memtupdeleted = 0;
|
||||
state->memtupcount = 0;
|
||||
state->tuples = 0;
|
||||
|
||||
/*
|
||||
* Initial size of array must be more than ALLOCSET_SEPARATE_THRESHOLD;
|
||||
@@ -433,6 +435,7 @@ tuplestore_clear(Tuplestorestate *state)
|
||||
state->truncated = false;
|
||||
state->memtupdeleted = 0;
|
||||
state->memtupcount = 0;
|
||||
state->tuples = 0;
|
||||
readptr = state->readptrs;
|
||||
for (i = 0; i < state->readptrcount; readptr++, i++)
|
||||
{
|
||||
@@ -533,6 +536,18 @@ tuplestore_select_read_pointer(Tuplestorestate *state, int ptr)
|
||||
state->activeptr = ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* tuplestore_tuple_count
|
||||
*
|
||||
* Returns the number of tuples added since creation or the last
|
||||
* tuplestore_clear().
|
||||
*/
|
||||
int64
|
||||
tuplestore_tuple_count(Tuplestorestate *state)
|
||||
{
|
||||
return state->tuples;
|
||||
}
|
||||
|
||||
/*
|
||||
* tuplestore_ateof
|
||||
*
|
||||
@@ -753,6 +768,8 @@ tuplestore_puttuple_common(Tuplestorestate *state, void *tuple)
|
||||
int i;
|
||||
ResourceOwner oldowner;
|
||||
|
||||
state->tuples++;
|
||||
|
||||
switch (state->status)
|
||||
{
|
||||
case TSS_INMEM:
|
||||
|
||||
Reference in New Issue
Block a user