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

Commit 3751b49

Browse files
committed
Number of tuples inserted/affected by INSERT/UPDATE/DELETE...
1 parent 40ac5a6 commit 3751b49

File tree

7 files changed

+116
-85
lines changed

7 files changed

+116
-85
lines changed

src/backend/executor/execMain.c

+21-20
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.19 1997/08/22 14:28:20 vadim Exp $
29+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.20 1997/08/27 09:02:24 vadim Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -65,7 +65,7 @@ static TupleTableSlot *ExecutePlan(EState *estate, Plan *plan,
6565
int numberTuples, ScanDirection direction,
6666
void (*printfunc)());
6767
static void ExecRetrieve(TupleTableSlot *slot, void (*printfunc)(),
68-
Relation intoRelationDesc);
68+
EState *estate);
6969
static void ExecAppend(TupleTableSlot *slot,ItemPointer tupleid,
7070
EState *estate);
7171
static void ExecDelete(TupleTableSlot *slot, ItemPointer tupleid,
@@ -171,6 +171,8 @@ ExecutorRun(QueryDesc *queryDesc, EState *estate, int feature, int count)
171171
plan = queryDesc->plantree;
172172
dest = queryDesc->dest;
173173
destination = (void (*)()) DestToFunction(dest);
174+
estate->es_processed = 0;
175+
estate->es_lastoid = InvalidOid;
174176

175177
#if 0
176178
/*
@@ -665,7 +667,6 @@ ExecutePlan(EState *estate,
665667
ScanDirection direction,
666668
void (*printfunc)())
667669
{
668-
Relation intoRelationDesc;
669670
JunkFilter *junkfilter;
670671

671672
TupleTableSlot *slot;
@@ -674,12 +675,6 @@ ExecutePlan(EState *estate,
674675
int current_tuple_count;
675676
TupleTableSlot *result;
676677

677-
/* ----------------
678-
* get information
679-
* ----------------
680-
*/
681-
intoRelationDesc = estate->es_into_relation_descriptor;
682-
683678
/* ----------------
684679
* initialize local variables
685680
* ----------------
@@ -780,9 +775,9 @@ ExecutePlan(EState *estate,
780775

781776
switch(operation) {
782777
case CMD_SELECT:
783-
ExecRetrieve(slot, /* slot containing tuple */
784-
printfunc, /* print function */
785-
intoRelationDesc); /* "into" relation */
778+
ExecRetrieve(slot, /* slot containing tuple */
779+
printfunc, /* print function */
780+
estate); /* */
786781
result = slot;
787782
break;
788783

@@ -853,7 +848,7 @@ ExecutePlan(EState *estate,
853848
static void
854849
ExecRetrieve(TupleTableSlot *slot,
855850
void (*printfunc)(),
856-
Relation intoRelationDesc)
851+
EState *estate)
857852
{
858853
HeapTuple tuple;
859854
TupleDesc attrtype;
@@ -869,9 +864,10 @@ ExecRetrieve(TupleTableSlot *slot,
869864
* insert the tuple into the "into relation"
870865
* ----------------
871866
*/
872-
if (intoRelationDesc != NULL) {
873-
heap_insert (intoRelationDesc, tuple);
874-
IncrAppended();
867+
if ( estate->es_into_relation_descriptor != NULL )
868+
{
869+
heap_insert (estate->es_into_relation_descriptor, tuple);
870+
IncrAppended();
875871
}
876872

877873
/* ----------------
@@ -880,6 +876,7 @@ ExecRetrieve(TupleTableSlot *slot,
880876
*/
881877
(*printfunc)(tuple, attrtype);
882878
IncrRetrieved();
879+
(estate->es_processed)++;
883880
}
884881

885882
/* ----------------------------------------------------------------
@@ -947,7 +944,6 @@ ExecAppend(TupleTableSlot *slot,
947944
newId = heap_insert(resultRelationDesc, /* relation desc */
948945
tuple); /* heap tuple */
949946
IncrAppended();
950-
UpdateAppendOid(newId);
951947

952948
/* ----------------
953949
* process indices
@@ -961,6 +957,8 @@ ExecAppend(TupleTableSlot *slot,
961957
if (numIndices > 0) {
962958
ExecInsertIndexTuples(slot, &(tuple->t_ctid), estate, false);
963959
}
960+
(estate->es_processed)++;
961+
estate->es_lastoid = newId;
964962
}
965963

966964
/* ----------------------------------------------------------------
@@ -989,10 +987,12 @@ ExecDelete(TupleTableSlot *slot,
989987
* delete the tuple
990988
* ----------------
991989
*/
992-
heap_delete(resultRelationDesc, /* relation desc */
993-
tupleid); /* item pointer to tuple */
994-
990+
if ( heap_delete(resultRelationDesc, /* relation desc */
991+
tupleid) ) /* item pointer to tuple */
992+
return;
993+
995994
IncrDeleted();
995+
(estate->es_processed)++;
996996

997997
/* ----------------
998998
* Note: Normally one would think that we have to
@@ -1094,6 +1094,7 @@ ExecReplace(TupleTableSlot *slot,
10941094
}
10951095

10961096
IncrReplaced();
1097+
(estate->es_processed)++;
10971098

10981099
/* ----------------
10991100
* Note: instead of having to update the old index tuples

src/backend/tcop/dest.c

+21-49
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.7 1997/08/19 21:34:02 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/dest.c,v 1.8 1997/08/27 09:03:14 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -43,8 +43,7 @@
4343

4444
#include "commands/async.h"
4545

46-
static Oid GetAppendOid(void);
47-
static void ResetAppendOid(void);
46+
static char CommandInfo[32] = {0};
4847

4948
/* ----------------
5049
* output functions
@@ -87,8 +86,6 @@ void (*DestToFunction(CommandDest dest))(HeapTuple, TupleDesc)
8786
return donothing;
8887
}
8988

90-
#define IS_INSERT_TAG(tag) (*tag == 'I' && *(tag+1) == 'N')
91-
9289
/* ----------------
9390
* EndCommand - tell destination that no more tuples will arrive
9491
* ----------------
@@ -106,14 +103,8 @@ EndCommand(char *commandTag, CommandDest dest)
106103
* ----------------
107104
*/
108105
pq_putnchar("C", 1);
109-
/* pq_putint(0, 4); */
110-
if (IS_INSERT_TAG(commandTag))
111-
{
112-
sprintf(buf, "%s %d", commandTag, GetAppendOid());
113-
pq_putstr(buf);
114-
}
115-
else
116-
pq_putstr(commandTag);
106+
sprintf(buf, "%s%s", commandTag, CommandInfo);
107+
pq_putstr(buf);
117108
pq_flush();
118109
break;
119110

@@ -239,7 +230,7 @@ BeginCommand(char *pname,
239230
* because nothing needs to be sent to the fe.
240231
* ----------------
241232
*/
242-
ResetAppendOid();
233+
CommandInfo[0] = 0;
243234
if (isIntoPortal)
244235
return;
245236

@@ -318,41 +309,22 @@ BeginCommand(char *pname,
318309
}
319310
}
320311

321-
static Oid AppendOid;
322-
323-
static void
324-
ResetAppendOid(void)
325-
{
326-
AppendOid = InvalidOid;
327-
}
328-
329-
#define MULTI_TUPLE_APPEND -1
330-
331312
void
332-
UpdateAppendOid(Oid newoid)
333-
{
334-
/*
335-
* First update after AppendOid was reset (at command beginning).
336-
*/
337-
if (AppendOid == InvalidOid)
338-
AppendOid = newoid;
339-
/*
340-
* Already detected a multiple tuple append, return a void oid ;)
341-
*/
342-
else if (AppendOid == MULTI_TUPLE_APPEND)
343-
return;
344-
/*
345-
* Oid has been assigned once before, tag this as a multiple tuple
346-
* append.
347-
*/
348-
else
349-
AppendOid = MULTI_TUPLE_APPEND;
350-
}
351-
352-
static Oid
353-
GetAppendOid(void)
313+
UpdateCommandInfo (int operation, Oid lastoid, uint32 tuples)
354314
{
355-
if (AppendOid == MULTI_TUPLE_APPEND)
356-
return InvalidOid;
357-
return AppendOid;
315+
switch (operation)
316+
{
317+
case CMD_INSERT :
318+
if ( tuples > 1 )
319+
lastoid = InvalidOid;
320+
sprintf (CommandInfo, " %u %u", lastoid, tuples);
321+
break;
322+
case CMD_DELETE :
323+
case CMD_UPDATE :
324+
sprintf (CommandInfo, " %u", tuples);
325+
break;
326+
default :
327+
CommandInfo[0] = 0;
328+
}
329+
return;
358330
}

src/backend/tcop/pquery.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.6 1997/08/19 21:34:07 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/pquery.c,v 1.7 1997/08/27 09:03:15 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -322,6 +322,9 @@ ProcessQueryDesc(QueryDesc *queryDesc)
322322
*/
323323
ExecutorRun(queryDesc, state, EXEC_RUN, 0);
324324

325+
/* save infos for EndCommand */
326+
UpdateCommandInfo (operation, state->es_lastoid, state->es_processed);
327+
325328
/* ----------------
326329
* now, we close down all the scans and free allocated resources...
327330
* with ExecutorEnd()

src/include/nodes/execnodes.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: execnodes.h,v 1.7 1997/08/06 03:42:02 momjian Exp $
9+
* $Id: execnodes.h,v 1.8 1997/08/27 09:04:52 vadim Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -197,6 +197,8 @@ typedef struct EState {
197197
TupleTable es_tupleTable;
198198
JunkFilter *es_junkFilter;
199199
int *es_refcount;
200+
uint32 es_processed; /* # of tuples processed */
201+
Oid es_lastoid; /* last oid processed (by INSERT) */
200202
} EState;
201203

202204
/* ----------------

src/include/tcop/dest.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* Copyright (c) 1994, Regents of the University of California
2828
*
29-
* $Id: dest.h,v 1.6 1997/08/19 21:40:06 momjian Exp $
29+
* $Id: dest.h,v 1.7 1997/08/27 09:05:09 vadim Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -69,6 +69,6 @@ extern void NullCommand(CommandDest dest);
6969
extern void BeginCommand(char *pname, int operation, TupleDesc attinfo,
7070
bool isIntoRel, bool isIntoPortal, char *tag,
7171
CommandDest dest);
72-
extern void UpdateAppendOid(Oid newoid);
72+
extern void UpdateCommandInfo (int operation, Oid lastoid, uint32 tuples);
7373

7474
#endif /* DEST_H */

src/interfaces/libpq/fe-exec.c

+63-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.33 1997/07/12 20:31:47 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.34 1997/08/27 09:05:23 vadim Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1532,18 +1532,70 @@ char* PQcmdStatus(PGresult *res) {
15321532
if the last command was an INSERT, return the oid string
15331533
if not, return ""
15341534
*/
1535-
const char* PQoidStatus(PGresult *res) {
1536-
if (!res) {
1537-
fprintf(stderr, "PQoidStatus() -- pointer to PQresult is null");
1538-
return NULL;
1539-
}
1535+
static char oidStatus[32] = {0};
1536+
const char* PQoidStatus (PGresult *res)
1537+
{
1538+
if (!res)
1539+
{
1540+
fprintf (stderr, "PQoidStatus () -- pointer to PQresult is null");
1541+
return NULL;
1542+
}
15401543

1541-
if (!res->cmdStatus)
1542-
return "";
1544+
oidStatus[0] = 0;
1545+
if ( !res->cmdStatus )
1546+
return oidStatus;
1547+
1548+
if ( strncmp (res->cmdStatus, "INSERT", 6) == 0 )
1549+
{
1550+
char *p = res->cmdStatus + 7;
1551+
char *e;
1552+
1553+
for (e = p; *e != ' ' && *e; ) e++;
1554+
sprintf (oidStatus, "%.*s", e - p, p);
1555+
}
1556+
return oidStatus;
1557+
}
15431558

1544-
if (strncmp(res->cmdStatus, "INSERT",6) == 0) {
1545-
return res->cmdStatus+7;
1546-
} else
1559+
/*
1560+
PQcmdTuples -
1561+
if the last command was an INSERT/UPDATE/DELETE, return number
1562+
of inserted/affected tuples, if not, return ""
1563+
*/
1564+
const char* PQcmdTuples (PGresult *res)
1565+
{
1566+
if (!res)
1567+
{
1568+
fprintf (stderr, "PQcmdTuples () -- pointer to PQresult is null");
1569+
return NULL;
1570+
}
1571+
1572+
if ( !res->cmdStatus )
1573+
return "";
1574+
1575+
if ( strncmp (res->cmdStatus, "INSERT", 6) == 0 ||
1576+
strncmp (res->cmdStatus, "DELETE", 6) == 0 ||
1577+
strncmp (res->cmdStatus, "UPDATE", 6) == 0 )
1578+
{
1579+
char *p = res->cmdStatus + 6;
1580+
1581+
if ( *p == 0 )
1582+
{
1583+
fprintf (stderr, "PQcmdTuples (%s) -- short input from server",
1584+
res->cmdStatus);
1585+
return NULL;
1586+
}
1587+
p++;
1588+
if ( *(res->cmdStatus) != 'I' ) /* UPDATE/DELETE */
1589+
return (p);
1590+
while ( *p != ' ' && *p ) p++; /* INSERT: skip oid */
1591+
if ( *p == 0 )
1592+
{
1593+
fprintf (stderr, "PQcmdTuples (INSERT) -- there's no # of tuples");
1594+
return NULL;
1595+
}
1596+
p++;
1597+
return (p);
1598+
}
15471599
return "";
15481600
}
15491601

0 commit comments

Comments
 (0)