Skip to content

Commit 8089517

Browse files
committed
Rename fields in pgstat structures for functions and relations
This commit renames the members of a few pgstat structures related to functions and relations, by respectively removing their prefix "f_" and "t_". The statistics for functions and relations and handled in their own file, and pgstatfuncs.c associates each field in a structure variable named based on the object type handled, so no information is lost with this rename. This will help with some of the refactoring aimed for pgstatfuncs.c, as this makes more consistent the field names with the SQL functions retrieving them. Author: Bertrand Drouvot Reviewed-by: Michael Paquier, Melanie Plageman Discussion: https://postgr.es/m/9142f62a-a422-145c-bde0-b5bc498a4ada@gmail.com
1 parent 11a0a8b commit 8089517

File tree

4 files changed

+142
-142
lines changed

4 files changed

+142
-142
lines changed

src/backend/utils/activity/pgstat_function.c

+23-23
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ pgstat_init_function_usage(FunctionCallInfo fcinfo,
124124
fcu->fs = pending;
125125

126126
/* save stats for this function, later used to compensate for recursion */
127-
fcu->save_f_total_time = pending->f_total_time;
127+
fcu->save_f_total_time = pending->total_time;
128128

129129
/* save current backend-wide total time */
130130
fcu->save_total = total_func_time;
131131

132132
/* get clock time as of function start */
133-
INSTR_TIME_SET_CURRENT(fcu->f_start);
133+
INSTR_TIME_SET_CURRENT(fcu->start);
134134
}
135135

136136
/*
@@ -146,41 +146,41 @@ void
146146
pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
147147
{
148148
PgStat_FunctionCounts *fs = fcu->fs;
149-
instr_time f_total;
150-
instr_time f_others;
151-
instr_time f_self;
149+
instr_time total;
150+
instr_time others;
151+
instr_time self;
152152

153153
/* stats not wanted? */
154154
if (fs == NULL)
155155
return;
156156

157157
/* total elapsed time in this function call */
158-
INSTR_TIME_SET_CURRENT(f_total);
159-
INSTR_TIME_SUBTRACT(f_total, fcu->f_start);
158+
INSTR_TIME_SET_CURRENT(total);
159+
INSTR_TIME_SUBTRACT(total, fcu->start);
160160

161161
/* self usage: elapsed minus anything already charged to other calls */
162-
f_others = total_func_time;
163-
INSTR_TIME_SUBTRACT(f_others, fcu->save_total);
164-
f_self = f_total;
165-
INSTR_TIME_SUBTRACT(f_self, f_others);
162+
others = total_func_time;
163+
INSTR_TIME_SUBTRACT(others, fcu->save_total);
164+
self = total;
165+
INSTR_TIME_SUBTRACT(self, others);
166166

167167
/* update backend-wide total time */
168-
INSTR_TIME_ADD(total_func_time, f_self);
168+
INSTR_TIME_ADD(total_func_time, self);
169169

170170
/*
171-
* Compute the new f_total_time as the total elapsed time added to the
172-
* pre-call value of f_total_time. This is necessary to avoid
171+
* Compute the new total_time as the total elapsed time added to the
172+
* pre-call value of total_time. This is necessary to avoid
173173
* double-counting any time taken by recursive calls of myself. (We do
174174
* not need any similar kluge for self time, since that already excludes
175175
* any recursive calls.)
176176
*/
177-
INSTR_TIME_ADD(f_total, fcu->save_f_total_time);
177+
INSTR_TIME_ADD(total, fcu->save_f_total_time);
178178

179179
/* update counters in function stats table */
180180
if (finalize)
181-
fs->f_numcalls++;
182-
fs->f_total_time = f_total;
183-
INSTR_TIME_ADD(fs->f_self_time, f_self);
181+
fs->numcalls++;
182+
fs->total_time = total;
183+
INSTR_TIME_ADD(fs->self_time, self);
184184
}
185185

186186
/*
@@ -203,11 +203,11 @@ pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
203203
if (!pgstat_lock_entry(entry_ref, nowait))
204204
return false;
205205

206-
shfuncent->stats.f_numcalls += localent->f_numcalls;
207-
shfuncent->stats.f_total_time +=
208-
INSTR_TIME_GET_MICROSEC(localent->f_total_time);
209-
shfuncent->stats.f_self_time +=
210-
INSTR_TIME_GET_MICROSEC(localent->f_self_time);
206+
shfuncent->stats.numcalls += localent->numcalls;
207+
shfuncent->stats.total_time +=
208+
INSTR_TIME_GET_MICROSEC(localent->total_time);
209+
shfuncent->stats.self_time +=
210+
INSTR_TIME_GET_MICROSEC(localent->self_time);
211211

212212
pgstat_unlock_entry(entry_ref);
213213

src/backend/utils/activity/pgstat_relation.c

+69-69
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ typedef struct TwoPhasePgStatRecord
3838
PgStat_Counter inserted_pre_truncdrop;
3939
PgStat_Counter updated_pre_truncdrop;
4040
PgStat_Counter deleted_pre_truncdrop;
41-
Oid t_id; /* table's OID */
42-
bool t_shared; /* is it a shared catalog? */
43-
bool t_truncdropped; /* was the relation truncated/dropped? */
41+
Oid id; /* table's OID */
42+
bool shared; /* is it a shared catalog? */
43+
bool truncdropped; /* was the relation truncated/dropped? */
4444
} TwoPhasePgStatRecord;
4545

4646

@@ -310,7 +310,7 @@ pgstat_report_analyze(Relation rel,
310310
deadtuples -= trans->tuples_updated + trans->tuples_deleted;
311311
}
312312
/* count stuff inserted by already-aborted subxacts, too */
313-
deadtuples -= rel->pgstat_info->t_counts.t_delta_dead_tuples;
313+
deadtuples -= rel->pgstat_info->counts.delta_dead_tuples;
314314
/* Since ANALYZE's counts are estimates, we could have underflowed */
315315
livetuples = Max(livetuples, 0);
316316
deadtuples = Max(deadtuples, 0);
@@ -385,13 +385,13 @@ pgstat_count_heap_update(Relation rel, bool hot, bool newpage)
385385
pgstat_info->trans->tuples_updated++;
386386

387387
/*
388-
* t_tuples_hot_updated and t_tuples_newpage_updated counters are
388+
* tuples_hot_updated and tuples_newpage_updated counters are
389389
* nontransactional, so just advance them
390390
*/
391391
if (hot)
392-
pgstat_info->t_counts.t_tuples_hot_updated++;
392+
pgstat_info->counts.tuples_hot_updated++;
393393
else if (newpage)
394-
pgstat_info->t_counts.t_tuples_newpage_updated++;
394+
pgstat_info->counts.tuples_newpage_updated++;
395395
}
396396
}
397397

@@ -432,7 +432,7 @@ pgstat_count_truncate(Relation rel)
432432
* update dead-tuples count
433433
*
434434
* The semantics of this are that we are reporting the nontransactional
435-
* recovery of "delta" dead tuples; so t_delta_dead_tuples decreases
435+
* recovery of "delta" dead tuples; so delta_dead_tuples decreases
436436
* rather than increasing, and the change goes straight into the per-table
437437
* counter, not into transactional state.
438438
*/
@@ -443,7 +443,7 @@ pgstat_update_heap_dead_tuples(Relation rel, int delta)
443443
{
444444
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
445445

446-
pgstat_info->t_counts.t_delta_dead_tuples -= delta;
446+
pgstat_info->counts.delta_dead_tuples -= delta;
447447
}
448448
}
449449

@@ -519,33 +519,33 @@ AtEOXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit)
519519
if (!isCommit)
520520
restore_truncdrop_counters(trans);
521521
/* count attempted actions regardless of commit/abort */
522-
tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
523-
tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
524-
tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
522+
tabstat->counts.tuples_inserted += trans->tuples_inserted;
523+
tabstat->counts.tuples_updated += trans->tuples_updated;
524+
tabstat->counts.tuples_deleted += trans->tuples_deleted;
525525
if (isCommit)
526526
{
527-
tabstat->t_counts.t_truncdropped = trans->truncdropped;
527+
tabstat->counts.truncdropped = trans->truncdropped;
528528
if (trans->truncdropped)
529529
{
530530
/* forget live/dead stats seen by backend thus far */
531-
tabstat->t_counts.t_delta_live_tuples = 0;
532-
tabstat->t_counts.t_delta_dead_tuples = 0;
531+
tabstat->counts.delta_live_tuples = 0;
532+
tabstat->counts.delta_dead_tuples = 0;
533533
}
534534
/* insert adds a live tuple, delete removes one */
535-
tabstat->t_counts.t_delta_live_tuples +=
535+
tabstat->counts.delta_live_tuples +=
536536
trans->tuples_inserted - trans->tuples_deleted;
537537
/* update and delete each create a dead tuple */
538-
tabstat->t_counts.t_delta_dead_tuples +=
538+
tabstat->counts.delta_dead_tuples +=
539539
trans->tuples_updated + trans->tuples_deleted;
540540
/* insert, update, delete each count as one change event */
541-
tabstat->t_counts.t_changed_tuples +=
541+
tabstat->counts.changed_tuples +=
542542
trans->tuples_inserted + trans->tuples_updated +
543543
trans->tuples_deleted;
544544
}
545545
else
546546
{
547547
/* inserted tuples are dead, deleted tuples are unaffected */
548-
tabstat->t_counts.t_delta_dead_tuples +=
548+
tabstat->counts.delta_dead_tuples +=
549549
trans->tuples_inserted + trans->tuples_updated;
550550
/* an aborted xact generates no changed_tuple events */
551551
}
@@ -625,11 +625,11 @@ AtEOSubXact_PgStat_Relations(PgStat_SubXactStatus *xact_state, bool isCommit, in
625625
/* first restore values obliterated by truncate/drop */
626626
restore_truncdrop_counters(trans);
627627
/* count attempted actions regardless of commit/abort */
628-
tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
629-
tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
630-
tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;
628+
tabstat->counts.tuples_inserted += trans->tuples_inserted;
629+
tabstat->counts.tuples_updated += trans->tuples_updated;
630+
tabstat->counts.tuples_deleted += trans->tuples_deleted;
631631
/* inserted tuples are dead, deleted tuples are unaffected */
632-
tabstat->t_counts.t_delta_dead_tuples +=
632+
tabstat->counts.delta_dead_tuples +=
633633
trans->tuples_inserted + trans->tuples_updated;
634634
tabstat->trans = trans->upper;
635635
pfree(trans);
@@ -662,9 +662,9 @@ AtPrepare_PgStat_Relations(PgStat_SubXactStatus *xact_state)
662662
record.inserted_pre_truncdrop = trans->inserted_pre_truncdrop;
663663
record.updated_pre_truncdrop = trans->updated_pre_truncdrop;
664664
record.deleted_pre_truncdrop = trans->deleted_pre_truncdrop;
665-
record.t_id = tabstat->t_id;
666-
record.t_shared = tabstat->t_shared;
667-
record.t_truncdropped = trans->truncdropped;
665+
record.id = tabstat->id;
666+
record.shared = tabstat->shared;
667+
record.truncdropped = trans->truncdropped;
668668

669669
RegisterTwoPhaseRecord(TWOPHASE_RM_PGSTAT_ID, 0,
670670
&record, sizeof(TwoPhasePgStatRecord));
@@ -706,24 +706,24 @@ pgstat_twophase_postcommit(TransactionId xid, uint16 info,
706706
PgStat_TableStatus *pgstat_info;
707707

708708
/* Find or create a tabstat entry for the rel */
709-
pgstat_info = pgstat_prep_relation_pending(rec->t_id, rec->t_shared);
709+
pgstat_info = pgstat_prep_relation_pending(rec->id, rec->shared);
710710

711711
/* Same math as in AtEOXact_PgStat, commit case */
712-
pgstat_info->t_counts.t_tuples_inserted += rec->tuples_inserted;
713-
pgstat_info->t_counts.t_tuples_updated += rec->tuples_updated;
714-
pgstat_info->t_counts.t_tuples_deleted += rec->tuples_deleted;
715-
pgstat_info->t_counts.t_truncdropped = rec->t_truncdropped;
716-
if (rec->t_truncdropped)
712+
pgstat_info->counts.tuples_inserted += rec->tuples_inserted;
713+
pgstat_info->counts.tuples_updated += rec->tuples_updated;
714+
pgstat_info->counts.tuples_deleted += rec->tuples_deleted;
715+
pgstat_info->counts.truncdropped = rec->truncdropped;
716+
if (rec->truncdropped)
717717
{
718718
/* forget live/dead stats seen by backend thus far */
719-
pgstat_info->t_counts.t_delta_live_tuples = 0;
720-
pgstat_info->t_counts.t_delta_dead_tuples = 0;
719+
pgstat_info->counts.delta_live_tuples = 0;
720+
pgstat_info->counts.delta_dead_tuples = 0;
721721
}
722-
pgstat_info->t_counts.t_delta_live_tuples +=
722+
pgstat_info->counts.delta_live_tuples +=
723723
rec->tuples_inserted - rec->tuples_deleted;
724-
pgstat_info->t_counts.t_delta_dead_tuples +=
724+
pgstat_info->counts.delta_dead_tuples +=
725725
rec->tuples_updated + rec->tuples_deleted;
726-
pgstat_info->t_counts.t_changed_tuples +=
726+
pgstat_info->counts.changed_tuples +=
727727
rec->tuples_inserted + rec->tuples_updated +
728728
rec->tuples_deleted;
729729
}
@@ -742,19 +742,19 @@ pgstat_twophase_postabort(TransactionId xid, uint16 info,
742742
PgStat_TableStatus *pgstat_info;
743743

744744
/* Find or create a tabstat entry for the rel */
745-
pgstat_info = pgstat_prep_relation_pending(rec->t_id, rec->t_shared);
745+
pgstat_info = pgstat_prep_relation_pending(rec->id, rec->shared);
746746

747747
/* Same math as in AtEOXact_PgStat, abort case */
748-
if (rec->t_truncdropped)
748+
if (rec->truncdropped)
749749
{
750750
rec->tuples_inserted = rec->inserted_pre_truncdrop;
751751
rec->tuples_updated = rec->updated_pre_truncdrop;
752752
rec->tuples_deleted = rec->deleted_pre_truncdrop;
753753
}
754-
pgstat_info->t_counts.t_tuples_inserted += rec->tuples_inserted;
755-
pgstat_info->t_counts.t_tuples_updated += rec->tuples_updated;
756-
pgstat_info->t_counts.t_tuples_deleted += rec->tuples_deleted;
757-
pgstat_info->t_counts.t_delta_dead_tuples +=
754+
pgstat_info->counts.tuples_inserted += rec->tuples_inserted;
755+
pgstat_info->counts.tuples_updated += rec->tuples_updated;
756+
pgstat_info->counts.tuples_deleted += rec->tuples_deleted;
757+
pgstat_info->counts.delta_dead_tuples +=
758758
rec->tuples_inserted + rec->tuples_updated;
759759
}
760760

@@ -785,7 +785,7 @@ pgstat_relation_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
785785
* Ignore entries that didn't accumulate any actual counts, such as
786786
* indexes that were opened by the planner but not used.
787787
*/
788-
if (memcmp(&lstats->t_counts, &all_zeroes,
788+
if (memcmp(&lstats->counts, &all_zeroes,
789789
sizeof(PgStat_TableCounts)) == 0)
790790
{
791791
return true;
@@ -797,38 +797,38 @@ pgstat_relation_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
797797
/* add the values to the shared entry. */
798798
tabentry = &shtabstats->stats;
799799

800-
tabentry->numscans += lstats->t_counts.t_numscans;
801-
if (lstats->t_counts.t_numscans)
800+
tabentry->numscans += lstats->counts.numscans;
801+
if (lstats->counts.numscans)
802802
{
803803
TimestampTz t = GetCurrentTransactionStopTimestamp();
804804

805805
if (t > tabentry->lastscan)
806806
tabentry->lastscan = t;
807807
}
808-
tabentry->tuples_returned += lstats->t_counts.t_tuples_returned;
809-
tabentry->tuples_fetched += lstats->t_counts.t_tuples_fetched;
810-
tabentry->tuples_inserted += lstats->t_counts.t_tuples_inserted;
811-
tabentry->tuples_updated += lstats->t_counts.t_tuples_updated;
812-
tabentry->tuples_deleted += lstats->t_counts.t_tuples_deleted;
813-
tabentry->tuples_hot_updated += lstats->t_counts.t_tuples_hot_updated;
814-
tabentry->tuples_newpage_updated += lstats->t_counts.t_tuples_newpage_updated;
808+
tabentry->tuples_returned += lstats->counts.tuples_returned;
809+
tabentry->tuples_fetched += lstats->counts.tuples_fetched;
810+
tabentry->tuples_inserted += lstats->counts.tuples_inserted;
811+
tabentry->tuples_updated += lstats->counts.tuples_updated;
812+
tabentry->tuples_deleted += lstats->counts.tuples_deleted;
813+
tabentry->tuples_hot_updated += lstats->counts.tuples_hot_updated;
814+
tabentry->tuples_newpage_updated += lstats->counts.tuples_newpage_updated;
815815

816816
/*
817817
* If table was truncated/dropped, first reset the live/dead counters.
818818
*/
819-
if (lstats->t_counts.t_truncdropped)
819+
if (lstats->counts.truncdropped)
820820
{
821821
tabentry->live_tuples = 0;
822822
tabentry->dead_tuples = 0;
823823
tabentry->ins_since_vacuum = 0;
824824
}
825825

826-
tabentry->live_tuples += lstats->t_counts.t_delta_live_tuples;
827-
tabentry->dead_tuples += lstats->t_counts.t_delta_dead_tuples;
828-
tabentry->mod_since_analyze += lstats->t_counts.t_changed_tuples;
829-
tabentry->ins_since_vacuum += lstats->t_counts.t_tuples_inserted;
830-
tabentry->blocks_fetched += lstats->t_counts.t_blocks_fetched;
831-
tabentry->blocks_hit += lstats->t_counts.t_blocks_hit;
826+
tabentry->live_tuples += lstats->counts.delta_live_tuples;
827+
tabentry->dead_tuples += lstats->counts.delta_dead_tuples;
828+
tabentry->mod_since_analyze += lstats->counts.changed_tuples;
829+
tabentry->ins_since_vacuum += lstats->counts.tuples_inserted;
830+
tabentry->blocks_fetched += lstats->counts.blocks_fetched;
831+
tabentry->blocks_hit += lstats->counts.blocks_hit;
832832

833833
/* Clamp live_tuples in case of negative delta_live_tuples */
834834
tabentry->live_tuples = Max(tabentry->live_tuples, 0);
@@ -839,13 +839,13 @@ pgstat_relation_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
839839

840840
/* The entry was successfully flushed, add the same to database stats */
841841
dbentry = pgstat_prep_database_pending(dboid);
842-
dbentry->tuples_returned += lstats->t_counts.t_tuples_returned;
843-
dbentry->tuples_fetched += lstats->t_counts.t_tuples_fetched;
844-
dbentry->tuples_inserted += lstats->t_counts.t_tuples_inserted;
845-
dbentry->tuples_updated += lstats->t_counts.t_tuples_updated;
846-
dbentry->tuples_deleted += lstats->t_counts.t_tuples_deleted;
847-
dbentry->blocks_fetched += lstats->t_counts.t_blocks_fetched;
848-
dbentry->blocks_hit += lstats->t_counts.t_blocks_hit;
842+
dbentry->tuples_returned += lstats->counts.tuples_returned;
843+
dbentry->tuples_fetched += lstats->counts.tuples_fetched;
844+
dbentry->tuples_inserted += lstats->counts.tuples_inserted;
845+
dbentry->tuples_updated += lstats->counts.tuples_updated;
846+
dbentry->tuples_deleted += lstats->counts.tuples_deleted;
847+
dbentry->blocks_fetched += lstats->counts.blocks_fetched;
848+
dbentry->blocks_hit += lstats->counts.blocks_hit;
849849

850850
return true;
851851
}
@@ -873,8 +873,8 @@ pgstat_prep_relation_pending(Oid rel_id, bool isshared)
873873
isshared ? InvalidOid : MyDatabaseId,
874874
rel_id, NULL);
875875
pending = entry_ref->pending;
876-
pending->t_id = rel_id;
877-
pending->t_shared = isshared;
876+
pending->id = rel_id;
877+
pending->shared = isshared;
878878

879879
return pending;
880880
}

0 commit comments

Comments
 (0)