Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit de28dc9

Browse files
committed
Portal and memory management infrastructure for extended query protocol.
Both plannable queries and utility commands are now always executed within Portals, which have been revamped so that they can handle the load (they used to be good only for single SELECT queries). Restructure code to push command-completion-tag selection logic out of postgres.c, so that it won't have to be duplicated between simple and extended queries. initdb forced due to addition of a field to Query nodes.
1 parent 1940434 commit de28dc9

File tree

33 files changed

+2200
-1688
lines changed

33 files changed

+2200
-1688
lines changed

contrib/intagg/int_aggregate.c

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ PG_FUNCTION_INFO_V1(int_enum);
7777

7878
/*
7979
* Manage the aggregation state of the array
80-
* You need to specify the correct memory context, or it will vanish!
80+
*
81+
* Need to specify a suitably long-lived memory context, or it will vanish!
82+
* PortalContext isn't really right, but it's close enough.
8183
*/
8284
static PGARRAY *
8385
GetPGArray(int4 state, int fAdd)
@@ -89,14 +91,7 @@ GetPGArray(int4 state, int fAdd)
8991
/* New array */
9092
int cb = PGARRAY_SIZE(START_NUM);
9193

92-
p = (PGARRAY *) MemoryContextAlloc(TopTransactionContext, cb);
93-
94-
if (!p)
95-
{
96-
elog(ERROR, "Integer aggregator, cant allocate TopTransactionContext memory");
97-
return 0;
98-
}
99-
94+
p = (PGARRAY *) MemoryContextAlloc(PortalContext, cb);
10095
p->a.size = cb;
10196
p->a.ndim = 0;
10297
p->a.flags = 0;
@@ -115,18 +110,6 @@ GetPGArray(int4 state, int fAdd)
115110
int cbNew = PGARRAY_SIZE(n);
116111

117112
pn = (PGARRAY *) repalloc(p, cbNew);
118-
119-
if (!pn)
120-
{ /* Realloc failed! Reallocate new block. */
121-
pn = (PGARRAY *) MemoryContextAlloc(TopTransactionContext, cbNew);
122-
if (!pn)
123-
{
124-
elog(ERROR, "Integer aggregator, REALLY REALLY can't alloc memory");
125-
return (PGARRAY *) NULL;
126-
}
127-
memcpy(pn, p, p->a.size);
128-
pfree(p);
129-
}
130113
pn->a.size = cbNew;
131114
pn->lower = n;
132115
return pn;
@@ -149,24 +132,19 @@ ShrinkPGArray(PGARRAY * p)
149132

150133
/* use current transaction context */
151134
pnew = palloc(cb);
152-
153-
if (pnew)
154-
{
155-
/*
156-
* Fix up the fields in the new structure, so Postgres
157-
* understands
158-
*/
159-
memcpy(pnew, p, cb);
160-
pnew->a.size = cb;
161-
pnew->a.ndim = 1;
162-
pnew->a.flags = 0;
135+
/*
136+
* Fix up the fields in the new structure, so Postgres
137+
* understands
138+
*/
139+
memcpy(pnew, p, cb);
140+
pnew->a.size = cb;
141+
pnew->a.ndim = 1;
142+
pnew->a.flags = 0;
163143
#ifndef PG_7_2
164-
pnew->a.elemtype = INT4OID;
144+
pnew->a.elemtype = INT4OID;
165145
#endif
166-
pnew->lower = 0;
167-
}
168-
else
169-
elog(ERROR, "Integer aggregator, can't allocate memory");
146+
pnew->lower = 0;
147+
170148
pfree(p);
171149
}
172150
return pnew;

doc/src/sgml/ref/postgres-ref.sgml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/ref/postgres-ref.sgml,v 1.32 2003/03/25 16:15:43 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/ref/postgres-ref.sgml,v 1.33 2003/05/02 20:54:33 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -28,7 +28,6 @@ PostgreSQL documentation
2828
<arg>-E</arg>
2929
<arg>-f<group choice="plain"><arg>s</arg><arg>i</arg><arg>t</arg><arg>n</arg><arg>m</arg><arg>h</arg></group></arg>
3030
<arg>-F</arg>
31-
<arg>-i</arg>
3231
<arg>-N</arg>
3332
<arg>-o <replaceable>filename</replaceable></arg>
3433
<arg>-O</arg>
@@ -52,7 +51,6 @@ PostgreSQL documentation
5251
<arg>-e</arg>
5352
<arg>-f<group choice="plain"><arg>s</arg><arg>i</arg><arg>t</arg><arg>n</arg><arg>m</arg><arg>h</arg></group></arg>
5453
<arg>-F</arg>
55-
<arg>-i</arg>
5654
<arg>-o <replaceable>filename</replaceable></arg>
5755
<arg>-O</arg>
5856
<arg>-p <replaceable>database</replaceable></arg>
@@ -281,15 +279,6 @@ PostgreSQL documentation
281279
</listitem>
282280
</varlistentry>
283281

284-
<varlistentry>
285-
<term><option>-i</option></term>
286-
<listitem>
287-
<para>
288-
Prevents query execution, but shows the plan tree.
289-
</para>
290-
</listitem>
291-
</varlistentry>
292-
293282
<varlistentry>
294283
<term><option>-O</option></term>
295284
<listitem>

src/backend/access/transam/xact.c

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.146 2003/04/26 20:22:59 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.147 2003/05/02 20:54:33 tgl Exp $
1212
*
1313
* NOTES
1414
* Transaction aborts can now occur two ways:
@@ -49,7 +49,7 @@
4949
* * CleanupTransaction() executes when we finally see a user COMMIT
5050
* or ROLLBACK command; it cleans things up and gets us out of
5151
* the transaction internally. In particular, we mustn't destroy
52-
* TransactionCommandContext until this point.
52+
* TopTransactionContext until this point.
5353
*
5454
* NOTES
5555
* The essential aspects of the transaction system are:
@@ -456,13 +456,12 @@ static void
456456
AtStart_Memory(void)
457457
{
458458
/*
459-
* We shouldn't have any transaction contexts already.
459+
* We shouldn't have a transaction context already.
460460
*/
461461
Assert(TopTransactionContext == NULL);
462-
Assert(TransactionCommandContext == NULL);
463462

464463
/*
465-
* Create a toplevel context for the transaction.
464+
* Create a toplevel context for the transaction, and make it active.
466465
*/
467466
TopTransactionContext =
468467
AllocSetContextCreate(TopMemoryContext,
@@ -471,16 +470,7 @@ AtStart_Memory(void)
471470
ALLOCSET_DEFAULT_INITSIZE,
472471
ALLOCSET_DEFAULT_MAXSIZE);
473472

474-
/*
475-
* Create a statement-level context and make it active.
476-
*/
477-
TransactionCommandContext =
478-
AllocSetContextCreate(TopTransactionContext,
479-
"TransactionCommandContext",
480-
ALLOCSET_DEFAULT_MINSIZE,
481-
ALLOCSET_DEFAULT_INITSIZE,
482-
ALLOCSET_DEFAULT_MAXSIZE);
483-
MemoryContextSwitchTo(TransactionCommandContext);
473+
MemoryContextSwitchTo(TopTransactionContext);
484474
}
485475

486476

@@ -659,7 +649,6 @@ AtCommit_Memory(void)
659649
Assert(TopTransactionContext != NULL);
660650
MemoryContextDelete(TopTransactionContext);
661651
TopTransactionContext = NULL;
662-
TransactionCommandContext = NULL;
663652
}
664653

665654
/* ----------------------------------------------------------------
@@ -769,19 +758,18 @@ AtAbort_Memory(void)
769758
{
770759
/*
771760
* Make sure we are in a valid context (not a child of
772-
* TransactionCommandContext...). Note that it is possible for this
761+
* TopTransactionContext...). Note that it is possible for this
773762
* code to be called when we aren't in a transaction at all; go
774763
* directly to TopMemoryContext in that case.
775764
*/
776-
if (TransactionCommandContext != NULL)
765+
if (TopTransactionContext != NULL)
777766
{
778-
MemoryContextSwitchTo(TransactionCommandContext);
767+
MemoryContextSwitchTo(TopTransactionContext);
779768

780769
/*
781-
* We do not want to destroy transaction contexts yet, but it
782-
* should be OK to delete any command-local memory.
770+
* We do not want to destroy the transaction's global state yet,
771+
* so we can't free any memory here.
783772
*/
784-
MemoryContextResetAndDeleteChildren(TransactionCommandContext);
785773
}
786774
else
787775
MemoryContextSwitchTo(TopMemoryContext);
@@ -812,7 +800,6 @@ AtCleanup_Memory(void)
812800
if (TopTransactionContext != NULL)
813801
MemoryContextDelete(TopTransactionContext);
814802
TopTransactionContext = NULL;
815-
TransactionCommandContext = NULL;
816803
}
817804

818805

@@ -926,7 +913,7 @@ CommitTransaction(void)
926913
* access, and in fact could still cause an error...)
927914
*/
928915

929-
AtEOXact_portals(true);
916+
AtCommit_Portals();
930917

931918
/* handle commit for large objects [ PA, 7/17/98 ] */
932919
/* XXX probably this does not belong here */
@@ -1057,7 +1044,7 @@ AbortTransaction(void)
10571044
* do abort processing
10581045
*/
10591046
DeferredTriggerAbortXact();
1060-
AtEOXact_portals(false);
1047+
AtAbort_Portals();
10611048
lo_commit(false); /* 'false' means it's abort */
10621049
AtAbort_Notify();
10631050
AtEOXact_UpdatePasswordFile(false);
@@ -1126,7 +1113,8 @@ CleanupTransaction(void)
11261113
/*
11271114
* do abort cleanup processing
11281115
*/
1129-
AtCleanup_Memory();
1116+
AtCleanup_Portals(); /* now safe to release portal memory */
1117+
AtCleanup_Memory(); /* and transaction memory */
11301118

11311119
/*
11321120
* done with abort processing, set current transaction state back to
@@ -1220,11 +1208,11 @@ StartTransactionCommand(bool preventChain)
12201208
}
12211209

12221210
/*
1223-
* We must switch to TransactionCommandContext before returning. This
1211+
* We must switch to TopTransactionContext before returning. This
12241212
* is already done if we called StartTransaction, otherwise not.
12251213
*/
1226-
Assert(TransactionCommandContext != NULL);
1227-
MemoryContextSwitchTo(TransactionCommandContext);
1214+
Assert(TopTransactionContext != NULL);
1215+
MemoryContextSwitchTo(TopTransactionContext);
12281216
}
12291217

12301218
/*
@@ -1266,7 +1254,6 @@ CommitTransactionCommand(bool forceCommit)
12661254
Assert(s->blockState == TBLOCK_INPROGRESS);
12671255
/* This code must match the TBLOCK_INPROGRESS case below: */
12681256
CommandCounterIncrement();
1269-
MemoryContextResetAndDeleteChildren(TransactionCommandContext);
12701257
}
12711258
break;
12721259

@@ -1283,15 +1270,10 @@ CommitTransactionCommand(bool forceCommit)
12831270
/*
12841271
* This is the case when we have finished executing a command
12851272
* someplace within a transaction block. We increment the
1286-
* command counter and return. Someday we may free resources
1287-
* local to the command.
1288-
*
1289-
* That someday is today, at least for memory allocated in
1290-
* TransactionCommandContext. - vadim 03/25/97
1273+
* command counter and return.
12911274
*/
12921275
case TBLOCK_INPROGRESS:
12931276
CommandCounterIncrement();
1294-
MemoryContextResetAndDeleteChildren(TransactionCommandContext);
12951277
break;
12961278

12971279
/*

src/backend/commands/cluster.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
*
1313
* IDENTIFICATION
14-
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.107 2003/03/20 03:34:55 momjian Exp $
14+
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.108 2003/05/02 20:54:33 tgl Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -189,10 +189,10 @@ cluster(ClusterStmt *stmt)
189189
/*
190190
* Create special memory context for cross-transaction storage.
191191
*
192-
* Since it is a child of QueryContext, it will go away even in case
192+
* Since it is a child of PortalContext, it will go away even in case
193193
* of error.
194194
*/
195-
cluster_context = AllocSetContextCreate(QueryContext,
195+
cluster_context = AllocSetContextCreate(PortalContext,
196196
"Cluster",
197197
ALLOCSET_DEFAULT_MINSIZE,
198198
ALLOCSET_DEFAULT_INITSIZE,

src/backend/commands/indexcmds.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.97 2003/01/23 15:18:40 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.98 2003/05/02 20:54:33 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -720,11 +720,11 @@ ReindexDatabase(const char *dbname, bool force, bool all)
720720

721721
/*
722722
* Create a memory context that will survive forced transaction
723-
* commits we do below. Since it is a child of QueryContext, it will
723+
* commits we do below. Since it is a child of PortalContext, it will
724724
* go away eventually even if we suffer an error; there's no need for
725725
* special abort cleanup logic.
726726
*/
727-
private_context = AllocSetContextCreate(QueryContext,
727+
private_context = AllocSetContextCreate(PortalContext,
728728
"ReindexDatabase",
729729
ALLOCSET_DEFAULT_MINSIZE,
730730
ALLOCSET_DEFAULT_INITSIZE,

0 commit comments

Comments
 (0)