@@ -74,7 +74,7 @@ int DefaultXactIsoLevel = XACT_READ_COMMITTED;
7474int XactIsoLevel ;
7575
7676bool DefaultXactReadOnly = false;
77- /*
77+ /*
7878 * We need initialization because only initialized vars appear in
7979 * postges.def and accssible from loadable extension
8080 */
@@ -119,6 +119,10 @@ TransactionId *ParallelCurrentXids;
119119 */
120120bool MyXactAccessedTempRel = false;
121121
122+ /*
123+ * Number of logical changes (insert,delte,update,lgical message) performed by transaction
124+ */
125+ int64 MyXactLogicalChanges = 0 ;
122126
123127/*
124128 * transaction states - transaction state from server perspective
@@ -1916,6 +1920,8 @@ StartTransaction(void)
19161920 XactIsoLevel = DefaultXactIsoLevel ;
19171921 forceSyncCommit = false;
19181922 MyXactAccessedTempRel = false;
1923+ MyXactLogicalChanges = 0 ;
1924+
19191925
19201926 /*
19211927 * reinitialize within-transaction counters
@@ -2181,7 +2187,7 @@ CommitTransaction(void)
21812187 * waiting for lock on a relation we've modified, we want them to know
21822188 * about the catalog change before they start using the relation).
21832189 */
2184- xactHasCatcacheInvalidationMessages = HasCatcacheInvalidationMessages ();
2190+ xactHasCatcacheInvalidationMessages = HasCatcacheInvalidationMessages ();
21852191 xactHasRelcacheInvalidationMessages = HasRelcacheInvalidationMessages ();
21862192 AtEOXact_Inval (true);
21872193
@@ -2196,7 +2202,7 @@ CommitTransaction(void)
21962202 RESOURCE_RELEASE_AFTER_LOCKS ,
21972203 true, true);
21982204
2199- if (!is_autonomous_transaction )
2205+ if (!is_autonomous_transaction )
22002206 {
22012207 /*
22022208 * Likewise, dropping of files deleted during the transaction is best done
@@ -2215,13 +2221,13 @@ CommitTransaction(void)
22152221
22162222 AtCommit_Notify ();
22172223 AtEOXact_GUC (true, s -> gucNestLevel );
2218- if (!is_autonomous_transaction )
2224+ if (!is_autonomous_transaction )
22192225 {
22202226 AtEOXact_SPI (true);
22212227 }
22222228 AtEOXact_on_commit_actions (true);
22232229 AtEOXact_Namespace (true, is_parallel_worker );
2224- if (!is_autonomous_transaction )
2230+ if (!is_autonomous_transaction )
22252231 {
22262232 AtEOXact_SMgr ();
22272233 AtEOXact_Files ();
@@ -2689,7 +2695,7 @@ AbortTransaction(void)
26892695 AtEOXact_Buffers (false);
26902696 }
26912697 AtEOXact_RelationCache (false);
2692- xactHasCatcacheInvalidationMessages = HasCatcacheInvalidationMessages ();
2698+ xactHasCatcacheInvalidationMessages = HasCatcacheInvalidationMessages ();
26932699 xactHasRelcacheInvalidationMessages = HasRelcacheInvalidationMessages ();
26942700 AtEOXact_Inval (false);
26952701 AtEOXact_MultiXact ();
@@ -3537,14 +3543,14 @@ void SuspendTransaction(void)
35373543 sus -> TopTransactionStateData = TopTransactionStateData ;
35383544
35393545 sus -> SnapshotState = SuspendSnapshot (); /* only before the resource-owner stuff */
3540-
3541- if (HasCatcacheInvalidationMessages ())
3546+
3547+ if (HasCatcacheInvalidationMessages ())
35423548 {
35433549 ResetCatalogCaches ();
35443550 }
3545- if (HasRelcacheInvalidationMessages ())
3551+ if (HasRelcacheInvalidationMessages ())
35463552 {
3547- RelationCacheInvalidate ();
3553+ RelationCacheInvalidate ();
35483554 }
35493555 sus -> InvalidationInfo = SuspendInvalidationInfo ();
35503556 xactHasCatcacheInvalidationMessages = false;
@@ -3601,7 +3607,7 @@ void SuspendTransaction(void)
36013607
36023608 sus -> PgStatState = PgStatSuspend ();
36033609 sus -> TriggerState = TriggerSuspend ();
3604- sus -> SPIState = SuspendSPI ();
3610+ sus -> SPIState = SuspendSPI ();
36053611 }
36063612
36073613 AtStart_Memory ();
@@ -3660,13 +3666,13 @@ bool ResumeTransaction(void)
36603666
36613667 ResumeSnapshot (sus -> SnapshotState ); /* only after the resource-owner stuff */
36623668 ResumeInvalidationInfo (sus -> InvalidationInfo );
3663- if (xactHasCatcacheInvalidationMessages )
3669+ if (xactHasCatcacheInvalidationMessages )
36643670 {
36653671 ResetCatalogCaches ();
36663672 }
3667- if (xactHasRelcacheInvalidationMessages )
3673+ if (xactHasRelcacheInvalidationMessages )
36683674 {
3669- RelationCacheInvalidate ();
3675+ RelationCacheInvalidate ();
36703676 }
36713677
36723678 MyProc -> backendId = sus -> vxid .backendId ;
@@ -3864,7 +3870,7 @@ EndTransactionBlock(bool autonomous)
38643870 * to COMMIT.
38653871 */
38663872 case TBLOCK_INPROGRESS :
3867- if (autonomous && getNestLevelATX () == 0 ) {
3873+ if (autonomous && getNestLevelATX () == 0 ) {
38683874 ereport (WARNING ,
38693875 (errcode (ERRCODE_NO_ACTIVE_SQL_TRANSACTION ),
38703876 errmsg ("there is no autonomous transaction in progress" )));
@@ -3993,7 +3999,7 @@ UserAbortTransactionBlock(bool autonomous)
39933999 * exit the transaction block.
39944000 */
39954001 case TBLOCK_INPROGRESS :
3996- if (autonomous && getNestLevelATX () == 0 ) {
4002+ if (autonomous && getNestLevelATX () == 0 ) {
39974003 ereport (WARNING ,
39984004 (errcode (ERRCODE_NO_ACTIVE_SQL_TRANSACTION ),
39994005 errmsg ("there is no autonomous transaction in progress" )));
@@ -5173,7 +5179,7 @@ EstimateTransactionStateSpace(void)
51735179 nxids = add_size (nxids , s -> nChildXids );
51745180 }
51755181
5176- nxids = add_size (nxids , nParallelCurrentXids );
5182+ nxids = add_size (nxids , nParallelCurrentXids );
51775183 nxids = mul_size (nxids , sizeof (TransactionId ));
51785184 return add_size (nxids , TM -> GetTransactionStateSize ());
51795185}
@@ -5489,6 +5495,7 @@ XactLogCommitRecord(TimestampTz commit_time,
54895495 /* First figure out and collect all the information needed */
54905496
54915497 xlrec .xact_time = commit_time ;
5498+ xlrec .n_changes = MyXactLogicalChanges ;
54925499
54935500 if (relcacheInval )
54945501 xl_xinfo .xinfo |= XACT_COMPLETION_UPDATE_RELCACHE_FILE ;
@@ -5890,7 +5897,7 @@ xact_redo_commit(xl_xact_parsed_commit *parsed,
58905897 * because subtransaction commit is never WAL logged.
58915898 */
58925899static void
5893- xact_redo_abort (xl_xact_parsed_abort * parsed ,
5900+ xact_redo_abort (xl_xact_parsed_abort * parsed ,
58945901 TransactionId xid ,
58955902 XLogRecPtr lsn ,
58965903 RepOriginId origin_id )
@@ -6036,9 +6043,9 @@ xact_redo(XLogReaderState *record)
60366043 RecreateTwoPhaseFile (XLogRecGetXid (record ),
60376044 XLogRecGetData (record ), XLogRecGetDataLen (record ));
60386045
6039- if (originId != InvalidRepOriginId && originId != DoNotReplicateId )
6046+ if (originId != InvalidRepOriginId && originId != DoNotReplicateId )
60406047 {
6041- xl_xact_parsed_prepare parsed ;
6048+ xl_xact_parsed_prepare parsed ;
60426049 ParsePrepareRecord (XLogRecGetXid (record ), XLogRecGetData (record ), & parsed );
60436050 Assert (parsed .origin_lsn != InvalidXLogRecPtr );
60446051 /* recover apply progress */
@@ -6059,17 +6066,17 @@ xact_redo(XLogReaderState *record)
60596066}
60606067
60616068Datum pg_current_tx_nest_level (PG_FUNCTION_ARGS )
6062- {
6069+ {
60636070 PG_RETURN_INT64 (GetCurrentTransactionNestLevel ());
60646071}
60656072
60666073Datum pg_current_atx_nest_level (PG_FUNCTION_ARGS )
6067- {
6074+ {
60686075 PG_RETURN_INT64 (getNestLevelATX ());
60696076}
60706077
60716078Datum pg_current_atx_has_ancestor (PG_FUNCTION_ARGS )
6072- {
6079+ {
60736080 int64 xid = PG_GETARG_INT64 (0 );
60746081 PG_RETURN_BOOL (TransactionIdIsAncestorOfCurrentATX (xid ));
60756082}
0 commit comments