Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit56ee2ec

Browse files
committed
Restructure command-completion-report code so that there is just one
report for each received SQL command, regardless of rewriting activity.Also ensure that this report comes from the 'original' command, not thelast command generated by rewrite; this fixes 7.2 breakage for INSERTcommands that have actions added by rules. Fernando Nasser and Tom Lane.
1 parentf71dc6d commit56ee2ec

File tree

17 files changed

+504
-272
lines changed

17 files changed

+504
-272
lines changed

‎src/backend/commands/command.c

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.154 2002/02/19 20:11:12 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.155 2002/02/26 22:47:04 tgl Exp $
1212
*
1313
* NOTES
1414
* The PerformAddAttribute() code, like most of the relation
@@ -89,16 +89,25 @@ PortalCleanup(Portal portal)
8989
MemoryContextSwitchTo(oldcontext);
9090
}
9191

92-
/* --------------------------------
93-
*PerformPortalFetch
94-
* --------------------------------
92+
93+
/*
94+
* PerformPortalFetch
95+
*
96+
*name: name of portal
97+
*forward: forward or backward fetch?
98+
*count: # of tuples to fetch (0 implies all)
99+
*dest: where to send results
100+
*completionTag: points to a buffer of size COMPLETION_TAG_BUFSIZE
101+
*in which to store a command completion status string.
102+
*
103+
* completionTag may be NULL if caller doesn't want a status string.
95104
*/
96105
void
97106
PerformPortalFetch(char*name,
98107
boolforward,
99108
intcount,
100-
char*tag,
101-
CommandDestdest)
109+
CommandDestdest,
110+
char*completionTag)
102111
{
103112
Portalportal;
104113
QueryDesc*queryDesc;
@@ -107,6 +116,10 @@ PerformPortalFetch(char *name,
107116
CommandIdsavedId;
108117
booltemp_desc= false;
109118

119+
/* initialize completion status in case of early exit */
120+
if (completionTag)
121+
strcpy(completionTag, (dest==None) ?"MOVE 0" :"FETCH 0");
122+
110123
/*
111124
* sanity checks
112125
*/
@@ -167,7 +180,7 @@ PerformPortalFetch(char *name,
167180
* relations */
168181
false,/* this is a portal fetch, not a "retrieve
169182
* portal" */
170-
tag,
183+
NULL,/* not used */
171184
queryDesc->dest);
172185

173186
/*
@@ -193,16 +206,15 @@ PerformPortalFetch(char *name,
193206
{
194207
ExecutorRun(queryDesc,estate,EXEC_FOR, (long)count);
195208

196-
/*
197-
* I use CMD_UPDATE, because no CMD_MOVE or the like exists,
198-
* and I would like to provide the same kind of info as
199-
* CMD_UPDATE
200-
*/
201-
UpdateCommandInfo(CMD_UPDATE,0,estate->es_processed);
202209
if (estate->es_processed>0)
203210
portal->atStart= false;/* OK to back up now */
204211
if (count <=0|| (int)estate->es_processed<count)
205212
portal->atEnd= true;/* we retrieved 'em all */
213+
214+
if (completionTag)
215+
snprintf(completionTag,COMPLETION_TAG_BUFSIZE,"%s %u",
216+
(dest==None) ?"MOVE" :"FETCH",
217+
estate->es_processed);
206218
}
207219
}
208220
else
@@ -211,16 +223,15 @@ PerformPortalFetch(char *name,
211223
{
212224
ExecutorRun(queryDesc,estate,EXEC_BACK, (long)count);
213225

214-
/*
215-
* I use CMD_UPDATE, because no CMD_MOVE or the like exists,
216-
* and I would like to provide the same kind of info as
217-
* CMD_UPDATE
218-
*/
219-
UpdateCommandInfo(CMD_UPDATE,0,estate->es_processed);
220226
if (estate->es_processed>0)
221227
portal->atEnd= false;/* OK to go forward now */
222228
if (count <=0|| (int)estate->es_processed<count)
223229
portal->atStart= true;/* we retrieved 'em all */
230+
231+
if (completionTag)
232+
snprintf(completionTag,COMPLETION_TAG_BUFSIZE,"%s %u",
233+
(dest==None) ?"MOVE" :"FETCH",
234+
estate->es_processed);
224235
}
225236
}
226237

@@ -236,11 +247,6 @@ PerformPortalFetch(char *name,
236247
pfree(queryDesc);
237248

238249
MemoryContextSwitchTo(oldcontext);
239-
240-
/*
241-
* Note: the "end-of-command" tag is returned by higher-level utility
242-
* code
243-
*/
244250
}
245251

246252
/* --------------------------------

‎src/backend/commands/explain.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994-5, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.67 2001/10/25 05:49:25 momjian Exp $
8+
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.68 2002/02/26 22:47:04 tgl Exp $
99
*
1010
*/
1111

@@ -120,7 +120,7 @@ ExplainOneQuery(Query *query, bool verbose, bool analyze, CommandDest dest)
120120
plan->instrument=InstrAlloc();
121121

122122
gettimeofday(&starttime,NULL);
123-
ProcessQuery(query,plan,None);
123+
ProcessQuery(query,plan,None,NULL);
124124
CommandCounterIncrement();
125125
gettimeofday(&endtime,NULL);
126126

‎src/backend/executor/functions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.47 2001/10/28 06:25:43 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/functions.c,v 1.48 2002/02/26 22:47:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -275,7 +275,7 @@ postquel_getnext(execution_state *es)
275275
/*
276276
* Process a utility command. (create, destroy...)DZ - 30-8-1996
277277
*/
278-
ProcessUtility(es->qd->parsetree->utilityStmt,es->qd->dest);
278+
ProcessUtility(es->qd->parsetree->utilityStmt,es->qd->dest,NULL);
279279
if (!LAST_POSTQUEL_COMMAND(es))
280280
CommandCounterIncrement();
281281
return (TupleTableSlot*)NULL;

‎src/backend/executor/spi.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/executor/spi.c,v 1.65 2002/02/14 15:24:08 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.66 2002/02/26 22:47:05 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1011,7 +1011,7 @@ _SPI_execute(char *src, int tcount, _SPI_plan *plan)
10111011
res=SPI_OK_UTILITY;
10121012
if (plan==NULL)
10131013
{
1014-
ProcessUtility(queryTree->utilityStmt,None);
1014+
ProcessUtility(queryTree->utilityStmt,None,NULL);
10151015
if (!islastquery)
10161016
CommandCounterIncrement();
10171017
else
@@ -1085,7 +1085,7 @@ _SPI_execute_plan(_SPI_plan *plan, Datum *Values, char *Nulls, int tcount)
10851085

10861086
if (queryTree->commandType==CMD_UTILITY)
10871087
{
1088-
ProcessUtility(queryTree->utilityStmt,None);
1088+
ProcessUtility(queryTree->utilityStmt,None,NULL);
10891089
if (!islastquery)
10901090
CommandCounterIncrement();
10911091
else

‎src/backend/nodes/copyfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.162 2002/02/24 20:20:20 tgl Exp $
18+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.163 2002/02/26 22:47:05 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -1755,6 +1755,7 @@ _copyQuery(Query *from)
17551755
newnode->isTemp=from->isTemp;
17561756
newnode->hasAggs=from->hasAggs;
17571757
newnode->hasSubLinks=from->hasSubLinks;
1758+
newnode->originalQuery=from->originalQuery;
17581759

17591760
Node_Copy(from,newnode,rtable);
17601761
Node_Copy(from,newnode,jointree);

‎src/backend/nodes/equalfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* Portions Copyright (c) 1994, Regents of the University of California
2121
*
2222
* IDENTIFICATION
23-
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.110 2002/02/24 20:20:20 tgl Exp $
23+
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.111 2002/02/26 22:47:05 tgl Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -593,6 +593,7 @@ _equalQuery(Query *a, Query *b)
593593
return false;
594594
if (a->hasSubLinks!=b->hasSubLinks)
595595
return false;
596+
/* we deliberately ignore originalQuery */
596597
if (!equal(a->rtable,b->rtable))
597598
return false;
598599
if (!equal(a->jointree,b->jointree))

‎src/backend/nodes/readfuncs.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.113 2001/10/25 05:49:31 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/nodes/readfuncs.c,v 1.114 2002/02/26 22:47:07 tgl Exp $
1212
*
1313
* NOTES
1414
* Most of the read functions for plan nodes are tested. (In fact, they
@@ -168,6 +168,9 @@ _readQuery(void)
168168
token=pg_strtok(&length);/* get hasSubLinks */
169169
local_node->hasSubLinks=strtobool(token);
170170

171+
/* we always want originalQuery to be false in a read-in query */
172+
local_node->originalQuery= false;
173+
171174
token=pg_strtok(&length);/* skip :rtable */
172175
local_node->rtable=nodeRead(true);
173176

‎src/backend/parser/analyze.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.214 2002/02/25 04:21:55 momjian Exp $
9+
*$Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.215 2002/02/26 22:47:08 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -122,10 +122,11 @@ parse_analyze(Node *parseTree, ParseState *parentParseState)
122122
{
123123
List*result=NIL;
124124
ParseState*pstate=make_parsestate(parentParseState);
125-
Query*query;
126125
/* Lists to return extra commands from transformation */
127-
List*extras_before=NIL;
128-
List*extras_after=NIL;
126+
List*extras_before=NIL;
127+
List*extras_after=NIL;
128+
Query*query;
129+
List*listscan;
129130

130131
query=transformStmt(pstate,parseTree,&extras_before,&extras_after);
131132
release_pstate_resources(pstate);
@@ -144,6 +145,18 @@ parse_analyze(Node *parseTree, ParseState *parentParseState)
144145
extras_after=lnext(extras_after);
145146
}
146147

148+
/*
149+
* Make sure that only the original query is marked original.
150+
* We have to do this explicitly since recursive calls of parse_analyze
151+
* will have set originalQuery in some of the added-on queries.
152+
*/
153+
foreach(listscan,result)
154+
{
155+
Query*q=lfirst(listscan);
156+
157+
q->originalQuery= (q==query);
158+
}
159+
147160
pfree(pstate);
148161

149162
returnresult;

‎src/backend/tcop/dest.c

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.46 2001/10/28 06:25:51 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.47 2002/02/26 22:47:08 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -41,8 +41,6 @@
4141
#include"libpq/pqformat.h"
4242

4343

44-
staticcharCommandInfo[32]= {0};
45-
4644
/* ----------------
4745
*dummy DestReceiver functions
4846
* ----------------
@@ -102,7 +100,6 @@ BeginCommand(char *pname,
102100
* if this is a "retrieve into portal" query, done because
103101
* nothing needs to be sent to the fe.
104102
*/
105-
CommandInfo[0]='\0';
106103
if (isIntoPortal)
107104
break;
108105

@@ -198,30 +195,22 @@ DestToFunction(CommandDest dest)
198195
}
199196

200197
/* ----------------
201-
*EndCommand - tell destination thatno more tuples will arrive
198+
*EndCommand - tell destination thatquery is complete
202199
* ----------------
203200
*/
204201
void
205-
EndCommand(char*commandTag,CommandDestdest)
202+
EndCommand(constchar*commandTag,CommandDestdest)
206203
{
207-
charbuf[64];
208-
209204
switch (dest)
210205
{
211206
caseRemote:
212207
caseRemoteInternal:
213-
214-
/*
215-
* tell the fe that the query is over
216-
*/
217-
sprintf(buf,"%s%s",commandTag,CommandInfo);
218-
pq_puttextmessage('C',buf);
219-
CommandInfo[0]='\0';
208+
pq_puttextmessage('C',commandTag);
220209
break;
221210

222-
caseDebug:
223211
caseNone:
224-
default:
212+
caseDebug:
213+
caseSPI:
225214
break;
226215
}
227216
}
@@ -317,23 +306,3 @@ ReadyForQuery(CommandDest dest)
317306
break;
318307
}
319308
}
320-
321-
void
322-
UpdateCommandInfo(intoperation,Oidlastoid,uint32tuples)
323-
{
324-
switch (operation)
325-
{
326-
caseCMD_INSERT:
327-
if (tuples>1)
328-
lastoid=InvalidOid;
329-
sprintf(CommandInfo," %u %u",lastoid,tuples);
330-
break;
331-
caseCMD_DELETE:
332-
caseCMD_UPDATE:
333-
sprintf(CommandInfo," %u",tuples);
334-
break;
335-
default:
336-
CommandInfo[0]='\0';
337-
break;
338-
}
339-
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp