PostgreSQL Source Code  git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
pgstat_relation.c File Reference
#include "postgres.h"
#include "access/twophase_rmgr.h"
#include "access/xact.h"
#include "catalog/catalog.h"
#include "utils/memutils.h"
#include "utils/pgstat_internal.h"
#include "utils/rel.h"
#include "utils/timestamp.h"
Include dependency graph for pgstat_relation.c:

Go to the source code of this file.

Data Structures

struct  TwoPhasePgStatRecord
 

Typedefs

typedef struct TwoPhasePgStatRecord TwoPhasePgStatRecord
 

Functions

static PgStat_TableStatuspgstat_prep_relation_pending (Oid rel_id, bool isshared)
 
static void add_tabstat_xact_level (PgStat_TableStatus *pgstat_info, int nest_level)
 
static void ensure_tabstat_xact_level (PgStat_TableStatus *pgstat_info)
 
static void save_truncdrop_counters (PgStat_TableXactStatus *trans, bool is_drop)
 
static void restore_truncdrop_counters (PgStat_TableXactStatus *trans)
 
void pgstat_copy_relation_stats (Relation dst, Relation src)
 
void pgstat_init_relation (Relation rel)
 
void pgstat_assoc_relation (Relation rel)
 
void pgstat_unlink_relation (Relation rel)
 
void pgstat_create_relation (Relation rel)
 
void pgstat_drop_relation (Relation rel)
 
void pgstat_report_vacuum (Oid tableoid, bool shared, PgStat_Counter livetuples, PgStat_Counter deadtuples)
 
void pgstat_report_analyze (Relation rel, PgStat_Counter livetuples, PgStat_Counter deadtuples, bool resetcounter)
 
void pgstat_count_heap_insert (Relation rel, PgStat_Counter n)
 
void pgstat_count_heap_update (Relation rel, bool hot, bool newpage)
 
void pgstat_count_heap_delete (Relation rel)
 
void pgstat_count_truncate (Relation rel)
 
void pgstat_update_heap_dead_tuples (Relation rel, int delta)
 
PgStat_StatTabEntrypgstat_fetch_stat_tabentry (Oid relid)
 
PgStat_StatTabEntrypgstat_fetch_stat_tabentry_ext (bool shared, Oid reloid)
 
PgStat_TableStatusfind_tabstat_entry (Oid rel_id)
 
void AtEOXact_PgStat_Relations (PgStat_SubXactStatus *xact_state, bool isCommit)
 
void AtEOSubXact_PgStat_Relations (PgStat_SubXactStatus *xact_state, bool isCommit, int nestDepth)
 
void AtPrepare_PgStat_Relations (PgStat_SubXactStatus *xact_state)
 
void PostPrepare_PgStat_Relations (PgStat_SubXactStatus *xact_state)
 
void pgstat_twophase_postcommit (TransactionId xid, uint16 info, void *recdata, uint32 len)
 
void pgstat_twophase_postabort (TransactionId xid, uint16 info, void *recdata, uint32 len)
 
bool pgstat_relation_flush_cb (PgStat_EntryRef *entry_ref, bool nowait)
 
void pgstat_relation_delete_pending_cb (PgStat_EntryRef *entry_ref)
 

Typedef Documentation

◆ TwoPhasePgStatRecord

Function Documentation

◆ add_tabstat_xact_level()

static void add_tabstat_xact_level ( PgStat_TableStatus pgstat_info,
int  nest_level 
)
static

Definition at line 913 of file pgstat_relation.c.

914 {
915  PgStat_SubXactStatus *xact_state;
917 
918  /*
919  * If this is the first rel to be modified at the current nest level, we
920  * first have to push a transaction stack entry.
921  */
922  xact_state = pgstat_get_xact_stack_level(nest_level);
923 
924  /* Now make a per-table stack entry */
927  sizeof(PgStat_TableXactStatus));
928  trans->nest_level = nest_level;
929  trans->upper = pgstat_info->trans;
930  trans->parent = pgstat_info;
931  trans->next = xact_state->first;
932  xact_state->first = trans;
933  pgstat_info->trans = trans;
934 }
MemoryContext TopTransactionContext
Definition: mcxt.c:154
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1215
PgStat_SubXactStatus * pgstat_get_xact_stack_level(int nest_level)
Definition: pgstat_xact.c:238
PgStat_TableXactStatus * first
struct PgStat_TableXactStatus * trans
Definition: pgstat.h:233
static zic_t trans[TZ_MAX_LEAPS]
Definition: zic.c:402

References PgStat_SubXactStatus::first, MemoryContextAllocZero(), pgstat_get_xact_stack_level(), TopTransactionContext, PgStat_TableStatus::trans, and trans.

Referenced by ensure_tabstat_xact_level().

◆ AtEOSubXact_PgStat_Relations()

void AtEOSubXact_PgStat_Relations ( PgStat_SubXactStatus xact_state,
bool  isCommit,
int  nestDepth 
)

Definition at line 594 of file pgstat_relation.c.

595 {
597  PgStat_TableXactStatus *next_trans;
598 
599  for (trans = xact_state->first; trans != NULL; trans = next_trans)
600  {
601  PgStat_TableStatus *tabstat;
602 
603  next_trans = trans->next;
604  Assert(trans->nest_level == nestDepth);
605  tabstat = trans->parent;
606  Assert(tabstat->trans == trans);
607 
608  if (isCommit)
609  {
610  if (trans->upper && trans->upper->nest_level == nestDepth - 1)
611  {
612  if (trans->truncdropped)
613  {
614  /* propagate the truncate/drop status one level up */
615  save_truncdrop_counters(trans->upper, false);
616  /* replace upper xact stats with ours */
617  trans->upper->tuples_inserted = trans->tuples_inserted;
618  trans->upper->tuples_updated = trans->tuples_updated;
619  trans->upper->tuples_deleted = trans->tuples_deleted;
620  }
621  else
622  {
623  trans->upper->tuples_inserted += trans->tuples_inserted;
624  trans->upper->tuples_updated += trans->tuples_updated;
625  trans->upper->tuples_deleted += trans->tuples_deleted;
626  }
627  tabstat->trans = trans->upper;
628  pfree(trans);
629  }
630  else
631  {
632  /*
633  * When there isn't an immediate parent state, we can just
634  * reuse the record instead of going through a palloc/pfree
635  * pushup (this works since it's all in TopTransactionContext
636  * anyway). We have to re-link it into the parent level,
637  * though, and that might mean pushing a new entry into the
638  * pgStatXactStack.
639  */
640  PgStat_SubXactStatus *upper_xact_state;
641 
642  upper_xact_state = pgstat_get_xact_stack_level(nestDepth - 1);
643  trans->next = upper_xact_state->first;
644  upper_xact_state->first = trans;
645  trans->nest_level = nestDepth - 1;
646  }
647  }
648  else
649  {
650  /*
651  * On abort, update top-level tabstat counts, then forget the
652  * subtransaction
653  */
654 
655  /* first restore values obliterated by truncate/drop */
657  /* count attempted actions regardless of commit/abort */
658  tabstat->counts.tuples_inserted += trans->tuples_inserted;
659  tabstat->counts.tuples_updated += trans->tuples_updated;
660  tabstat->counts.tuples_deleted += trans->tuples_deleted;
661  /* inserted tuples are dead, deleted tuples are unaffected */
662  tabstat->counts.delta_dead_tuples +=
663  trans->tuples_inserted + trans->tuples_updated;
664  tabstat->trans = trans->upper;
665  pfree(trans);
666  }
667  }
668 }
#define Assert(condition)
Definition: c.h:837
void pfree(void *pointer)
Definition: mcxt.c:1521
static void save_truncdrop_counters(PgStat_TableXactStatus *trans, bool is_drop)
static void restore_truncdrop_counters(PgStat_TableXactStatus *trans)
PgStat_Counter tuples_inserted
Definition: pgstat.h:199
PgStat_Counter tuples_updated
Definition: pgstat.h:200
PgStat_Counter delta_dead_tuples
Definition: pgstat.h:207
PgStat_Counter tuples_deleted
Definition: pgstat.h:201
PgStat_TableCounts counts
Definition: pgstat.h:234

References Assert, PgStat_TableStatus::counts, PgStat_TableCounts::delta_dead_tuples, PgStat_SubXactStatus::first, pfree(), pgstat_get_xact_stack_level(), restore_truncdrop_counters(), save_truncdrop_counters(), PgStat_TableStatus::trans, trans, PgStat_TableCounts::tuples_deleted, PgStat_TableCounts::tuples_inserted, and PgStat_TableCounts::tuples_updated.

Referenced by AtEOSubXact_PgStat().

◆ AtEOXact_PgStat_Relations()

void AtEOXact_PgStat_Relations ( PgStat_SubXactStatus xact_state,
bool  isCommit 
)

Definition at line 536 of file pgstat_relation.c.

537 {
539 
540  for (trans = xact_state->first; trans != NULL; trans = trans->next)
541  {
542  PgStat_TableStatus *tabstat;
543 
544  Assert(trans->nest_level == 1);
545  Assert(trans->upper == NULL);
546  tabstat = trans->parent;
547  Assert(tabstat->trans == trans);
548  /* restore pre-truncate/drop stats (if any) in case of aborted xact */
549  if (!isCommit)
551  /* count attempted actions regardless of commit/abort */
552  tabstat->counts.tuples_inserted += trans->tuples_inserted;
553  tabstat->counts.tuples_updated += trans->tuples_updated;
554  tabstat->counts.tuples_deleted += trans->tuples_deleted;
555  if (isCommit)
556  {
557  tabstat->counts.truncdropped = trans->truncdropped;
558  if (trans->truncdropped)
559  {
560  /* forget live/dead stats seen by backend thus far */
561  tabstat->counts.delta_live_tuples = 0;
562  tabstat->counts.delta_dead_tuples = 0;
563  }
564  /* insert adds a live tuple, delete removes one */
565  tabstat->counts.delta_live_tuples +=
566  trans->tuples_inserted - trans->tuples_deleted;
567  /* update and delete each create a dead tuple */
568  tabstat->counts.delta_dead_tuples +=
569  trans->tuples_updated + trans->tuples_deleted;
570  /* insert, update, delete each count as one change event */
571  tabstat->counts.changed_tuples +=
572  trans->tuples_inserted + trans->tuples_updated +
573  trans->tuples_deleted;
574  }
575  else
576  {
577  /* inserted tuples are dead, deleted tuples are unaffected */
578  tabstat->counts.delta_dead_tuples +=
579  trans->tuples_inserted + trans->tuples_updated;
580  /* an aborted xact generates no changed_tuple events */
581  }
582  tabstat->trans = NULL;
583  }
584 }
PgStat_Counter delta_live_tuples
Definition: pgstat.h:206
PgStat_Counter changed_tuples
Definition: pgstat.h:208

References Assert, PgStat_TableCounts::changed_tuples, PgStat_TableStatus::counts, PgStat_TableCounts::delta_dead_tuples, PgStat_TableCounts::delta_live_tuples, PgStat_SubXactStatus::first, restore_truncdrop_counters(), PgStat_TableStatus::trans, trans, PgStat_TableCounts::truncdropped, PgStat_TableCounts::tuples_deleted, PgStat_TableCounts::tuples_inserted, and PgStat_TableCounts::tuples_updated.

Referenced by AtEOXact_PgStat().

◆ AtPrepare_PgStat_Relations()

void AtPrepare_PgStat_Relations ( PgStat_SubXactStatus xact_state)

Definition at line 675 of file pgstat_relation.c.

676 {
678 
679  for (trans = xact_state->first; trans != NULL; trans = trans->next)
680  {
682  TwoPhasePgStatRecord record;
683 
684  Assert(trans->nest_level == 1);
685  Assert(trans->upper == NULL);
686  tabstat = trans->parent;
687  Assert(tabstat->trans == trans);
688 
689  record.tuples_inserted = trans->tuples_inserted;
690  record.tuples_updated = trans->tuples_updated;
691  record.tuples_deleted = trans->tuples_deleted;
692  record.inserted_pre_truncdrop = trans->inserted_pre_truncdrop;
693  record.updated_pre_truncdrop = trans->updated_pre_truncdrop;
694  record.deleted_pre_truncdrop = trans->deleted_pre_truncdrop;
695  record.id = tabstat->id;
696  record.shared = tabstat->shared;
697  record.truncdropped = trans->truncdropped;
698 
700  &record, sizeof(TwoPhasePgStatRecord));
701  }
702 }
#define PG_USED_FOR_ASSERTS_ONLY
Definition: c.h:197
PgStat_Counter deleted_pre_truncdrop
PgStat_Counter inserted_pre_truncdrop
PgStat_Counter updated_pre_truncdrop
PgStat_Counter tuples_deleted
PgStat_Counter tuples_inserted
PgStat_Counter tuples_updated
void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info, const void *data, uint32 len)
Definition: twophase.c:1280
#define TWOPHASE_RM_PGSTAT_ID
Definition: twophase_rmgr.h:26

References Assert, TwoPhasePgStatRecord::deleted_pre_truncdrop, PgStat_SubXactStatus::first, TwoPhasePgStatRecord::id, TwoPhasePgStatRecord::inserted_pre_truncdrop, PG_USED_FOR_ASSERTS_ONLY, RegisterTwoPhaseRecord(), TwoPhasePgStatRecord::shared, trans, TwoPhasePgStatRecord::truncdropped, TwoPhasePgStatRecord::tuples_deleted, TwoPhasePgStatRecord::tuples_inserted, TwoPhasePgStatRecord::tuples_updated, TWOPHASE_RM_PGSTAT_ID, and TwoPhasePgStatRecord::updated_pre_truncdrop.

Referenced by AtPrepare_PgStat().

◆ ensure_tabstat_xact_level()

static void ensure_tabstat_xact_level ( PgStat_TableStatus pgstat_info)
static

Definition at line 940 of file pgstat_relation.c.

941 {
942  int nest_level = GetCurrentTransactionNestLevel();
943 
944  if (pgstat_info->trans == NULL ||
945  pgstat_info->trans->nest_level != nest_level)
946  add_tabstat_xact_level(pgstat_info, nest_level);
947 }
static void add_tabstat_xact_level(PgStat_TableStatus *pgstat_info, int nest_level)
int GetCurrentTransactionNestLevel(void)
Definition: xact.c:928

References add_tabstat_xact_level(), GetCurrentTransactionNestLevel(), PgStat_TableXactStatus::nest_level, and PgStat_TableStatus::trans.

Referenced by pgstat_count_heap_delete(), pgstat_count_heap_insert(), pgstat_count_heap_update(), and pgstat_count_truncate().

◆ find_tabstat_entry()

PgStat_TableStatus* find_tabstat_entry ( Oid  rel_id)

Definition at line 486 of file pgstat_relation.c.

487 {
488  PgStat_EntryRef *entry_ref;
490  PgStat_TableStatus *tabentry = NULL;
491  PgStat_TableStatus *tablestatus = NULL;
492 
494  if (!entry_ref)
495  {
497  if (!entry_ref)
498  return tablestatus;
499  }
500 
501  tabentry = (PgStat_TableStatus *) entry_ref->pending;
502  tablestatus = palloc(sizeof(PgStat_TableStatus));
503  *tablestatus = *tabentry;
504 
505  /*
506  * Reset tablestatus->trans in the copy of PgStat_TableStatus as it may
507  * point to a shared memory area. Its data is saved below, so removing it
508  * does not matter.
509  */
510  tablestatus->trans = NULL;
511 
512  /*
513  * Live subtransaction counts are not included yet. This is not a hot
514  * code path so reconcile tuples_inserted, tuples_updated and
515  * tuples_deleted even if the caller may not be interested in this data.
516  */
517  for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
518  {
519  tablestatus->counts.tuples_inserted += trans->tuples_inserted;
520  tablestatus->counts.tuples_updated += trans->tuples_updated;
521  tablestatus->counts.tuples_deleted += trans->tuples_deleted;
522  }
523 
524  return tablestatus;
525 }
Oid MyDatabaseId
Definition: globals.c:93
void * palloc(Size size)
Definition: mcxt.c:1317
PgStat_EntryRef * pgstat_fetch_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:1311
#define PGSTAT_KIND_RELATION
Definition: pgstat.h:48
#define InvalidOid
Definition: postgres_ext.h:36

References PgStat_TableStatus::counts, InvalidOid, MyDatabaseId, palloc(), PgStat_EntryRef::pending, pgstat_fetch_pending_entry(), PGSTAT_KIND_RELATION, PgStat_TableStatus::trans, trans, PgStat_TableCounts::tuples_deleted, PgStat_TableCounts::tuples_inserted, and PgStat_TableCounts::tuples_updated.

◆ pgstat_assoc_relation()

void pgstat_assoc_relation ( Relation  rel)

Definition at line 131 of file pgstat_relation.c.

132 {
133  Assert(rel->pgstat_enabled);
134  Assert(rel->pgstat_info == NULL);
135 
136  /* Else find or make the PgStat_TableStatus entry, and update link */
138  rel->rd_rel->relisshared);
139 
140  /* don't allow link a stats to multiple relcache entries */
141  Assert(rel->pgstat_info->relation == NULL);
142 
143  /* mark this relation as the owner */
144  rel->pgstat_info->relation = rel;
145 }
static PgStat_TableStatus * pgstat_prep_relation_pending(Oid rel_id, bool isshared)
#define RelationGetRelid(relation)
Definition: rel.h:505
Relation relation
Definition: pgstat.h:235
bool pgstat_enabled
Definition: rel.h:253
Form_pg_class rd_rel
Definition: rel.h:111
struct PgStat_TableStatus * pgstat_info
Definition: rel.h:255

References Assert, RelationData::pgstat_enabled, RelationData::pgstat_info, pgstat_prep_relation_pending(), RelationData::rd_rel, PgStat_TableStatus::relation, and RelationGetRelid.

◆ pgstat_copy_relation_stats()

void pgstat_copy_relation_stats ( Relation  dst,
Relation  src 
)

Definition at line 57 of file pgstat_relation.c.

58 {
59  PgStat_StatTabEntry *srcstats;
60  PgStatShared_Relation *dstshstats;
61  PgStat_EntryRef *dst_ref;
62 
63  srcstats = pgstat_fetch_stat_tabentry_ext(src->rd_rel->relisshared,
64  RelationGetRelid(src));
65  if (!srcstats)
66  return;
67 
69  dst->rd_rel->relisshared ? InvalidOid : MyDatabaseId,
70  RelationGetRelid(dst),
71  false);
72 
73  dstshstats = (PgStatShared_Relation *) dst_ref->shared_stats;
74  dstshstats->stats = *srcstats;
75 
76  pgstat_unlock_entry(dst_ref);
77 }
PgStat_StatTabEntry * pgstat_fetch_stat_tabentry_ext(bool shared, Oid reloid)
void pgstat_unlock_entry(PgStat_EntryRef *entry_ref)
Definition: pgstat_shmem.c:675
PgStat_EntryRef * pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait)
Definition: pgstat_shmem.c:684
PgStat_StatTabEntry stats
PgStatShared_Common * shared_stats

References InvalidOid, MyDatabaseId, pgstat_fetch_stat_tabentry_ext(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_RELATION, pgstat_unlock_entry(), RelationData::rd_rel, RelationGetRelid, PgStat_EntryRef::shared_stats, and PgStatShared_Relation::stats.

Referenced by index_concurrently_swap().

◆ pgstat_count_heap_delete()

void pgstat_count_heap_delete ( Relation  rel)

Definition at line 400 of file pgstat_relation.c.

401 {
403  {
404  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
405 
406  ensure_tabstat_xact_level(pgstat_info);
407  pgstat_info->trans->tuples_deleted++;
408  }
409 }
#define pgstat_should_count_relation(rel)
Definition: pgstat.h:643
static void ensure_tabstat_xact_level(PgStat_TableStatus *pgstat_info)
PgStat_Counter tuples_deleted
Definition: pgstat.h:246

References ensure_tabstat_xact_level(), RelationData::pgstat_info, pgstat_should_count_relation, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_deleted.

Referenced by heap_abort_speculative(), and heap_delete().

◆ pgstat_count_heap_insert()

void pgstat_count_heap_insert ( Relation  rel,
PgStat_Counter  n 
)

Definition at line 359 of file pgstat_relation.c.

360 {
362  {
363  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
364 
365  ensure_tabstat_xact_level(pgstat_info);
366  pgstat_info->trans->tuples_inserted += n;
367  }
368 }
PgStat_Counter tuples_inserted
Definition: pgstat.h:244

References ensure_tabstat_xact_level(), RelationData::pgstat_info, pgstat_should_count_relation, PgStat_TableStatus::trans, and PgStat_TableXactStatus::tuples_inserted.

Referenced by heap_insert(), heap_multi_insert(), and RefreshMatViewByOid().

◆ pgstat_count_heap_update()

void pgstat_count_heap_update ( Relation  rel,
bool  hot,
bool  newpage 
)

Definition at line 374 of file pgstat_relation.c.

375 {
376  Assert(!(hot && newpage));
377 
379  {
380  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
381 
382  ensure_tabstat_xact_level(pgstat_info);
383  pgstat_info->trans->tuples_updated++;
384 
385  /*
386  * tuples_hot_updated and tuples_newpage_updated counters are
387  * nontransactional, so just advance them
388  */
389  if (hot)
390  pgstat_info->counts.tuples_hot_updated++;
391  else if (newpage)
392  pgstat_info->counts.tuples_newpage_updated++;
393  }
394 }
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:202
PgStat_Counter tuples_newpage_updated
Definition: pgstat.h:203
PgStat_Counter tuples_updated
Definition: pgstat.h:245

References Assert, PgStat_TableStatus::counts, ensure_tabstat_xact_level(), RelationData::pgstat_info, pgstat_should_count_relation, PgStat_TableStatus::trans, PgStat_TableCounts::tuples_hot_updated, PgStat_TableCounts::tuples_newpage_updated, and PgStat_TableXactStatus::tuples_updated.

Referenced by heap_update().

◆ pgstat_count_truncate()

void pgstat_count_truncate ( Relation  rel)

◆ pgstat_create_relation()

void pgstat_create_relation ( Relation  rel)

Definition at line 168 of file pgstat_relation.c.

169 {
171  rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId,
172  RelationGetRelid(rel));
173 }
void pgstat_create_transactional(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat_xact.c:361

References InvalidOid, MyDatabaseId, pgstat_create_transactional(), PGSTAT_KIND_RELATION, RelationData::rd_rel, and RelationGetRelid.

Referenced by heap_create().

◆ pgstat_drop_relation()

void pgstat_drop_relation ( Relation  rel)

Definition at line 179 of file pgstat_relation.c.

180 {
181  int nest_level = GetCurrentTransactionNestLevel();
182  PgStat_TableStatus *pgstat_info;
183 
185  rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId,
186  RelationGetRelid(rel));
187 
189  return;
190 
191  /*
192  * Transactionally set counters to 0. That ensures that accesses to
193  * pg_stat_xact_all_tables inside the transaction show 0.
194  */
195  pgstat_info = rel->pgstat_info;
196  if (pgstat_info->trans &&
197  pgstat_info->trans->nest_level == nest_level)
198  {
199  save_truncdrop_counters(pgstat_info->trans, true);
200  pgstat_info->trans->tuples_inserted = 0;
201  pgstat_info->trans->tuples_updated = 0;
202  pgstat_info->trans->tuples_deleted = 0;
203  }
204 }
void pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat_xact.c:384

References GetCurrentTransactionNestLevel(), InvalidOid, MyDatabaseId, PgStat_TableXactStatus::nest_level, pgstat_drop_transactional(), RelationData::pgstat_info, PGSTAT_KIND_RELATION, pgstat_should_count_relation, RelationData::rd_rel, RelationGetRelid, save_truncdrop_counters(), PgStat_TableStatus::trans, PgStat_TableXactStatus::tuples_deleted, PgStat_TableXactStatus::tuples_inserted, and PgStat_TableXactStatus::tuples_updated.

Referenced by heap_drop_with_catalog(), and index_drop().

◆ pgstat_fetch_stat_tabentry()

PgStat_StatTabEntry* pgstat_fetch_stat_tabentry ( Oid  relid)

Definition at line 455 of file pgstat_relation.c.

456 {
457  return pgstat_fetch_stat_tabentry_ext(IsSharedRelation(relid), relid);
458 }
bool IsSharedRelation(Oid relationId)
Definition: catalog.c:273

References IsSharedRelation(), and pgstat_fetch_stat_tabentry_ext().

◆ pgstat_fetch_stat_tabentry_ext()

PgStat_StatTabEntry* pgstat_fetch_stat_tabentry_ext ( bool  shared,
Oid  reloid 
)

Definition at line 465 of file pgstat_relation.c.

466 {
467  Oid dboid = (shared ? InvalidOid : MyDatabaseId);
468 
469  return (PgStat_StatTabEntry *)
471 }
void * pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid)
Definition: pgstat.c:939
unsigned int Oid
Definition: postgres_ext.h:31

References InvalidOid, MyDatabaseId, pgstat_fetch_entry(), and PGSTAT_KIND_RELATION.

Referenced by do_autovacuum(), pgstat_copy_relation_stats(), pgstat_fetch_stat_tabentry(), and recheck_relation_needs_vacanalyze().

◆ pgstat_init_relation()

void pgstat_init_relation ( Relation  rel)

Definition at line 91 of file pgstat_relation.c.

92 {
93  char relkind = rel->rd_rel->relkind;
94 
95  /*
96  * We only count stats for relations with storage and partitioned tables
97  */
98  if (!RELKIND_HAS_STORAGE(relkind) && relkind != RELKIND_PARTITIONED_TABLE)
99  {
100  rel->pgstat_enabled = false;
101  rel->pgstat_info = NULL;
102  return;
103  }
104 
105  if (!pgstat_track_counts)
106  {
107  if (rel->pgstat_info)
109 
110  /* We're not counting at all */
111  rel->pgstat_enabled = false;
112  rel->pgstat_info = NULL;
113  return;
114  }
115 
116  rel->pgstat_enabled = true;
117 }
bool pgstat_track_counts
Definition: pgstat.c:203
void pgstat_unlink_relation(Relation rel)

References RelationData::pgstat_enabled, RelationData::pgstat_info, pgstat_track_counts, pgstat_unlink_relation(), and RelationData::rd_rel.

Referenced by relation_open(), and try_relation_open().

◆ pgstat_prep_relation_pending()

static PgStat_TableStatus * pgstat_prep_relation_pending ( Oid  rel_id,
bool  isshared 
)
static

Definition at line 894 of file pgstat_relation.c.

895 {
896  PgStat_EntryRef *entry_ref;
897  PgStat_TableStatus *pending;
898 
900  isshared ? InvalidOid : MyDatabaseId,
901  rel_id, NULL);
902  pending = entry_ref->pending;
903  pending->id = rel_id;
904  pending->shared = isshared;
905 
906  return pending;
907 }
PgStat_EntryRef * pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool *created_entry)
Definition: pgstat.c:1273

References PgStat_TableStatus::id, InvalidOid, MyDatabaseId, PgStat_EntryRef::pending, PGSTAT_KIND_RELATION, pgstat_prep_pending_entry(), and PgStat_TableStatus::shared.

Referenced by pgstat_assoc_relation(), pgstat_twophase_postabort(), and pgstat_twophase_postcommit().

◆ pgstat_relation_delete_pending_cb()

void pgstat_relation_delete_pending_cb ( PgStat_EntryRef entry_ref)

Definition at line 881 of file pgstat_relation.c.

882 {
883  PgStat_TableStatus *pending = (PgStat_TableStatus *) entry_ref->pending;
884 
885  if (pending->relation)
887 }
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:76

References if(), PgStat_EntryRef::pending, pgstat_unlink_relation(), and PgStat_TableStatus::relation.

◆ pgstat_relation_flush_cb()

bool pgstat_relation_flush_cb ( PgStat_EntryRef entry_ref,
bool  nowait 
)

Definition at line 801 of file pgstat_relation.c.

802 {
803  Oid dboid;
804  PgStat_TableStatus *lstats; /* pending stats entry */
805  PgStatShared_Relation *shtabstats;
806  PgStat_StatTabEntry *tabentry; /* table entry of shared stats */
807  PgStat_StatDBEntry *dbentry; /* pending database entry */
808 
809  dboid = entry_ref->shared_entry->key.dboid;
810  lstats = (PgStat_TableStatus *) entry_ref->pending;
811  shtabstats = (PgStatShared_Relation *) entry_ref->shared_stats;
812 
813  /*
814  * Ignore entries that didn't accumulate any actual counts, such as
815  * indexes that were opened by the planner but not used.
816  */
817  if (pg_memory_is_all_zeros(&lstats->counts,
818  sizeof(struct PgStat_TableCounts)))
819  return true;
820 
821  if (!pgstat_lock_entry(entry_ref, nowait))
822  return false;
823 
824  /* add the values to the shared entry. */
825  tabentry = &shtabstats->stats;
826 
827  tabentry->numscans += lstats->counts.numscans;
828  if (lstats->counts.numscans)
829  {
831 
832  if (t > tabentry->lastscan)
833  tabentry->lastscan = t;
834  }
835  tabentry->tuples_returned += lstats->counts.tuples_returned;
836  tabentry->tuples_fetched += lstats->counts.tuples_fetched;
837  tabentry->tuples_inserted += lstats->counts.tuples_inserted;
838  tabentry->tuples_updated += lstats->counts.tuples_updated;
839  tabentry->tuples_deleted += lstats->counts.tuples_deleted;
840  tabentry->tuples_hot_updated += lstats->counts.tuples_hot_updated;
842 
843  /*
844  * If table was truncated/dropped, first reset the live/dead counters.
845  */
846  if (lstats->counts.truncdropped)
847  {
848  tabentry->live_tuples = 0;
849  tabentry->dead_tuples = 0;
850  tabentry->ins_since_vacuum = 0;
851  }
852 
853  tabentry->live_tuples += lstats->counts.delta_live_tuples;
854  tabentry->dead_tuples += lstats->counts.delta_dead_tuples;
855  tabentry->mod_since_analyze += lstats->counts.changed_tuples;
856  tabentry->ins_since_vacuum += lstats->counts.tuples_inserted;
857  tabentry->blocks_fetched += lstats->counts.blocks_fetched;
858  tabentry->blocks_hit += lstats->counts.blocks_hit;
859 
860  /* Clamp live_tuples in case of negative delta_live_tuples */
861  tabentry->live_tuples = Max(tabentry->live_tuples, 0);
862  /* Likewise for dead_tuples */
863  tabentry->dead_tuples = Max(tabentry->dead_tuples, 0);
864 
865  pgstat_unlock_entry(entry_ref);
866 
867  /* The entry was successfully flushed, add the same to database stats */
868  dbentry = pgstat_prep_database_pending(dboid);
869  dbentry->tuples_returned += lstats->counts.tuples_returned;
870  dbentry->tuples_fetched += lstats->counts.tuples_fetched;
871  dbentry->tuples_inserted += lstats->counts.tuples_inserted;
872  dbentry->tuples_updated += lstats->counts.tuples_updated;
873  dbentry->tuples_deleted += lstats->counts.tuples_deleted;
874  dbentry->blocks_fetched += lstats->counts.blocks_fetched;
875  dbentry->blocks_hit += lstats->counts.blocks_hit;
876 
877  return true;
878 }
#define Max(x, y)
Definition: c.h:977
int64 TimestampTz
Definition: timestamp.h:39
static bool pg_memory_is_all_zeros(const void *ptr, size_t len)
Definition: memutils.h:219
PgStat_StatDBEntry * pgstat_prep_database_pending(Oid dboid)
bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait)
Definition: pgstat_shmem.c:647
PgStatShared_HashEntry * shared_entry
PgStat_Counter tuples_updated
Definition: pgstat.h:366
PgStat_Counter tuples_inserted
Definition: pgstat.h:365
PgStat_Counter tuples_returned
Definition: pgstat.h:363
PgStat_Counter blocks_hit
Definition: pgstat.h:362
PgStat_Counter blocks_fetched
Definition: pgstat.h:361
PgStat_Counter tuples_deleted
Definition: pgstat.h:367
PgStat_Counter tuples_fetched
Definition: pgstat.h:364
PgStat_Counter tuples_fetched
Definition: pgstat.h:442
PgStat_Counter ins_since_vacuum
Definition: pgstat.h:453
PgStat_Counter blocks_hit
Definition: pgstat.h:456
PgStat_Counter mod_since_analyze
Definition: pgstat.h:452
PgStat_Counter tuples_deleted
Definition: pgstat.h:446
PgStat_Counter tuples_hot_updated
Definition: pgstat.h:447
PgStat_Counter tuples_updated
Definition: pgstat.h:445
PgStat_Counter live_tuples
Definition: pgstat.h:450
PgStat_Counter numscans
Definition: pgstat.h:438
PgStat_Counter dead_tuples
Definition: pgstat.h:451
PgStat_Counter blocks_fetched
Definition: pgstat.h:455
PgStat_Counter tuples_returned
Definition: pgstat.h:441
TimestampTz lastscan
Definition: pgstat.h:439
PgStat_Counter tuples_inserted
Definition: pgstat.h:444
PgStat_Counter tuples_newpage_updated
Definition: pgstat.h:448
PgStat_Counter blocks_hit
Definition: pgstat.h:211
PgStat_Counter numscans
Definition: pgstat.h:194
PgStat_Counter tuples_returned
Definition: pgstat.h:196
PgStat_Counter blocks_fetched
Definition: pgstat.h:210
PgStat_Counter tuples_fetched
Definition: pgstat.h:197
TimestampTz GetCurrentTransactionStopTimestamp(void)
Definition: xact.c:890

References PgStat_TableCounts::blocks_fetched, PgStat_StatDBEntry::blocks_fetched, PgStat_StatTabEntry::blocks_fetched, PgStat_TableCounts::blocks_hit, PgStat_StatDBEntry::blocks_hit, PgStat_StatTabEntry::blocks_hit, PgStat_TableCounts::changed_tuples, PgStat_TableStatus::counts, PgStat_HashKey::dboid, PgStat_StatTabEntry::dead_tuples, PgStat_TableCounts::delta_dead_tuples, PgStat_TableCounts::delta_live_tuples, GetCurrentTransactionStopTimestamp(), PgStat_StatTabEntry::ins_since_vacuum, PgStatShared_HashEntry::key, PgStat_StatTabEntry::lastscan, PgStat_StatTabEntry::live_tuples, Max, PgStat_StatTabEntry::mod_since_analyze, PgStat_TableCounts::numscans, PgStat_StatTabEntry::numscans, PgStat_EntryRef::pending, pg_memory_is_all_zeros(), pgstat_lock_entry(), pgstat_prep_database_pending(), pgstat_unlock_entry(), PgStat_EntryRef::shared_entry, PgStat_EntryRef::shared_stats, PgStatShared_Relation::stats, PgStat_TableCounts::truncdropped, PgStat_TableCounts::tuples_deleted, PgStat_StatDBEntry::tuples_deleted, PgStat_StatTabEntry::tuples_deleted, PgStat_TableCounts::tuples_fetched, PgStat_StatDBEntry::tuples_fetched, PgStat_StatTabEntry::tuples_fetched, PgStat_TableCounts::tuples_hot_updated, PgStat_StatTabEntry::tuples_hot_updated, PgStat_TableCounts::tuples_inserted, PgStat_StatDBEntry::tuples_inserted, PgStat_StatTabEntry::tuples_inserted, PgStat_TableCounts::tuples_newpage_updated, PgStat_StatTabEntry::tuples_newpage_updated, PgStat_TableCounts::tuples_returned, PgStat_StatDBEntry::tuples_returned, PgStat_StatTabEntry::tuples_returned, PgStat_TableCounts::tuples_updated, PgStat_StatDBEntry::tuples_updated, and PgStat_StatTabEntry::tuples_updated.

◆ pgstat_report_analyze()

void pgstat_report_analyze ( Relation  rel,
PgStat_Counter  livetuples,
PgStat_Counter  deadtuples,
bool  resetcounter 
)

Definition at line 276 of file pgstat_relation.c.

279 {
280  PgStat_EntryRef *entry_ref;
281  PgStatShared_Relation *shtabentry;
282  PgStat_StatTabEntry *tabentry;
283  Oid dboid = (rel->rd_rel->relisshared ? InvalidOid : MyDatabaseId);
284 
285  if (!pgstat_track_counts)
286  return;
287 
288  /*
289  * Unlike VACUUM, ANALYZE might be running inside a transaction that has
290  * already inserted and/or deleted rows in the target table. ANALYZE will
291  * have counted such rows as live or dead respectively. Because we will
292  * report our counts of such rows at transaction end, we should subtract
293  * off these counts from the update we're making now, else they'll be
294  * double-counted after commit. (This approach also ensures that the
295  * shared stats entry ends up with the right numbers if we abort instead
296  * of committing.)
297  *
298  * Waste no time on partitioned tables, though.
299  */
300  if (pgstat_should_count_relation(rel) &&
301  rel->rd_rel->relkind != RELKIND_PARTITIONED_TABLE)
302  {
304 
305  for (trans = rel->pgstat_info->trans; trans; trans = trans->upper)
306  {
307  livetuples -= trans->tuples_inserted - trans->tuples_deleted;
308  deadtuples -= trans->tuples_updated + trans->tuples_deleted;
309  }
310  /* count stuff inserted by already-aborted subxacts, too */
311  deadtuples -= rel->pgstat_info->counts.delta_dead_tuples;
312  /* Since ANALYZE's counts are estimates, we could have underflowed */
313  livetuples = Max(livetuples, 0);
314  deadtuples = Max(deadtuples, 0);
315  }
316 
317  /* block acquiring lock for the same reason as pgstat_report_autovac() */
319  RelationGetRelid(rel),
320  false);
321  /* can't get dropped while accessed */
322  Assert(entry_ref != NULL && entry_ref->shared_stats != NULL);
323 
324  shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
325  tabentry = &shtabentry->stats;
326 
327  tabentry->live_tuples = livetuples;
328  tabentry->dead_tuples = deadtuples;
329 
330  /*
331  * If commanded, reset mod_since_analyze to zero. This forgets any
332  * changes that were committed while the ANALYZE was in progress, but we
333  * have no good way to estimate how many of those there were.
334  */
335  if (resetcounter)
336  tabentry->mod_since_analyze = 0;
337 
339  {
341  tabentry->autoanalyze_count++;
342  }
343  else
344  {
346  tabentry->analyze_count++;
347  }
348 
349  pgstat_unlock_entry(entry_ref);
350 
351  /* see pgstat_report_vacuum() */
352  pgstat_flush_io(false);
353 }
TimestampTz GetCurrentTimestamp(void)
Definition: timestamp.c:1644
#define AmAutoVacuumWorkerProcess()
Definition: miscadmin.h:373
void pgstat_flush_io(bool nowait)
Definition: pgstat_io.c:177
PgStat_Counter analyze_count
Definition: pgstat.h:463
TimestampTz last_analyze_time
Definition: pgstat.h:462
PgStat_Counter autoanalyze_count
Definition: pgstat.h:465
TimestampTz last_autoanalyze_time
Definition: pgstat.h:464

References AmAutoVacuumWorkerProcess, PgStat_StatTabEntry::analyze_count, Assert, PgStat_StatTabEntry::autoanalyze_count, PgStat_TableStatus::counts, PgStat_StatTabEntry::dead_tuples, PgStat_TableCounts::delta_dead_tuples, GetCurrentTimestamp(), if(), InvalidOid, PgStat_StatTabEntry::last_analyze_time, PgStat_StatTabEntry::last_autoanalyze_time, PgStat_StatTabEntry::live_tuples, Max, PgStat_StatTabEntry::mod_since_analyze, MyDatabaseId, pgstat_flush_io(), pgstat_get_entry_ref_locked(), RelationData::pgstat_info, PGSTAT_KIND_RELATION, pgstat_should_count_relation, pgstat_track_counts, pgstat_unlock_entry(), RelationData::rd_rel, RelationGetRelid, PgStat_EntryRef::shared_stats, PgStatShared_Relation::stats, PgStat_TableStatus::trans, and trans.

Referenced by do_analyze_rel().

◆ pgstat_report_vacuum()

void pgstat_report_vacuum ( Oid  tableoid,
bool  shared,
PgStat_Counter  livetuples,
PgStat_Counter  deadtuples 
)

Definition at line 210 of file pgstat_relation.c.

212 {
213  PgStat_EntryRef *entry_ref;
214  PgStatShared_Relation *shtabentry;
215  PgStat_StatTabEntry *tabentry;
216  Oid dboid = (shared ? InvalidOid : MyDatabaseId);
217  TimestampTz ts;
218 
219  if (!pgstat_track_counts)
220  return;
221 
222  /* Store the data in the table's hash table entry. */
223  ts = GetCurrentTimestamp();
224 
225  /* block acquiring lock for the same reason as pgstat_report_autovac() */
227  dboid, tableoid, false);
228 
229  shtabentry = (PgStatShared_Relation *) entry_ref->shared_stats;
230  tabentry = &shtabentry->stats;
231 
232  tabentry->live_tuples = livetuples;
233  tabentry->dead_tuples = deadtuples;
234 
235  /*
236  * It is quite possible that a non-aggressive VACUUM ended up skipping
237  * various pages, however, we'll zero the insert counter here regardless.
238  * It's currently used only to track when we need to perform an "insert"
239  * autovacuum, which are mainly intended to freeze newly inserted tuples.
240  * Zeroing this may just mean we'll not try to vacuum the table again
241  * until enough tuples have been inserted to trigger another insert
242  * autovacuum. An anti-wraparound autovacuum will catch any persistent
243  * stragglers.
244  */
245  tabentry->ins_since_vacuum = 0;
246 
248  {
249  tabentry->last_autovacuum_time = ts;
250  tabentry->autovacuum_count++;
251  }
252  else
253  {
254  tabentry->last_vacuum_time = ts;
255  tabentry->vacuum_count++;
256  }
257 
258  pgstat_unlock_entry(entry_ref);
259 
260  /*
261  * Flush IO statistics now. pgstat_report_stat() will flush IO stats,
262  * however this will not be called until after an entire autovacuum cycle
263  * is done -- which will likely vacuum many relations -- or until the
264  * VACUUM command has processed all tables and committed.
265  */
266  pgstat_flush_io(false);
267 }
PgStat_Counter vacuum_count
Definition: pgstat.h:459
TimestampTz last_autovacuum_time
Definition: pgstat.h:460
PgStat_Counter autovacuum_count
Definition: pgstat.h:461
TimestampTz last_vacuum_time
Definition: pgstat.h:458

References AmAutoVacuumWorkerProcess, PgStat_StatTabEntry::autovacuum_count, PgStat_StatTabEntry::dead_tuples, GetCurrentTimestamp(), if(), PgStat_StatTabEntry::ins_since_vacuum, InvalidOid, PgStat_StatTabEntry::last_autovacuum_time, PgStat_StatTabEntry::last_vacuum_time, PgStat_StatTabEntry::live_tuples, MyDatabaseId, pgstat_flush_io(), pgstat_get_entry_ref_locked(), PGSTAT_KIND_RELATION, pgstat_track_counts, pgstat_unlock_entry(), PgStat_EntryRef::shared_stats, PgStatShared_Relation::stats, and PgStat_StatTabEntry::vacuum_count.

Referenced by heap_vacuum_rel().

◆ pgstat_twophase_postabort()

void pgstat_twophase_postabort ( TransactionId  xid,
uint16  info,
void *  recdata,
uint32  len 
)

◆ pgstat_twophase_postcommit()

void pgstat_twophase_postcommit ( TransactionId  xid,
uint16  info,
void *  recdata,
uint32  len 
)

Definition at line 732 of file pgstat_relation.c.

734 {
735  TwoPhasePgStatRecord *rec = (TwoPhasePgStatRecord *) recdata;
736  PgStat_TableStatus *pgstat_info;
737 
738  /* Find or create a tabstat entry for the rel */
739  pgstat_info = pgstat_prep_relation_pending(rec->id, rec->shared);
740 
741  /* Same math as in AtEOXact_PgStat, commit case */
742  pgstat_info->counts.tuples_inserted += rec->tuples_inserted;
743  pgstat_info->counts.tuples_updated += rec->tuples_updated;
744  pgstat_info->counts.tuples_deleted += rec->tuples_deleted;
745  pgstat_info->counts.truncdropped = rec->truncdropped;
746  if (rec->truncdropped)
747  {
748  /* forget live/dead stats seen by backend thus far */
749  pgstat_info->counts.delta_live_tuples = 0;
750  pgstat_info->counts.delta_dead_tuples = 0;
751  }
752  pgstat_info->counts.delta_live_tuples +=
753  rec->tuples_inserted - rec->tuples_deleted;
754  pgstat_info->counts.delta_dead_tuples +=
755  rec->tuples_updated + rec->tuples_deleted;
756  pgstat_info->counts.changed_tuples +=
757  rec->tuples_inserted + rec->tuples_updated +
758  rec->tuples_deleted;
759 }

References PgStat_TableCounts::changed_tuples, PgStat_TableStatus::counts, PgStat_TableCounts::delta_dead_tuples, PgStat_TableCounts::delta_live_tuples, TwoPhasePgStatRecord::id, pgstat_prep_relation_pending(), TwoPhasePgStatRecord::shared, TwoPhasePgStatRecord::truncdropped, PgStat_TableCounts::truncdropped, TwoPhasePgStatRecord::tuples_deleted, PgStat_TableCounts::tuples_deleted, TwoPhasePgStatRecord::tuples_inserted, PgStat_TableCounts::tuples_inserted, TwoPhasePgStatRecord::tuples_updated, and PgStat_TableCounts::tuples_updated.

◆ pgstat_unlink_relation()

void pgstat_unlink_relation ( Relation  rel)

Definition at line 152 of file pgstat_relation.c.

153 {
154  /* remove the link to stats info if any */
155  if (rel->pgstat_info == NULL)
156  return;
157 
158  /* link sanity check */
159  Assert(rel->pgstat_info->relation == rel);
160  rel->pgstat_info->relation = NULL;
161  rel->pgstat_info = NULL;
162 }

References Assert, RelationData::pgstat_info, and PgStat_TableStatus::relation.

Referenced by pgstat_init_relation(), pgstat_relation_delete_pending_cb(), and RelationDestroyRelation().

◆ pgstat_update_heap_dead_tuples()

void pgstat_update_heap_dead_tuples ( Relation  rel,
int  delta 
)

Definition at line 438 of file pgstat_relation.c.

439 {
441  {
442  PgStat_TableStatus *pgstat_info = rel->pgstat_info;
443 
444  pgstat_info->counts.delta_dead_tuples -= delta;
445  }
446 }

References PgStat_TableStatus::counts, PgStat_TableCounts::delta_dead_tuples, RelationData::pgstat_info, and pgstat_should_count_relation.

Referenced by heap_page_prune_opt().

◆ PostPrepare_PgStat_Relations()

void PostPrepare_PgStat_Relations ( PgStat_SubXactStatus xact_state)

Definition at line 713 of file pgstat_relation.c.

714 {
716 
717  for (trans = xact_state->first; trans != NULL; trans = trans->next)
718  {
719  PgStat_TableStatus *tabstat;
720 
721  tabstat = trans->parent;
722  tabstat->trans = NULL;
723  }
724 }

References PgStat_SubXactStatus::first, PgStat_TableStatus::trans, and trans.

Referenced by PostPrepare_PgStat().

◆ restore_truncdrop_counters()

static void restore_truncdrop_counters ( PgStat_TableXactStatus trans)
static

Definition at line 974 of file pgstat_relation.c.

975 {
976  if (trans->truncdropped)
977  {
978  trans->tuples_inserted = trans->inserted_pre_truncdrop;
979  trans->tuples_updated = trans->updated_pre_truncdrop;
980  trans->tuples_deleted = trans->deleted_pre_truncdrop;
981  }
982 }

References trans.

Referenced by AtEOSubXact_PgStat_Relations(), and AtEOXact_PgStat_Relations().

◆ save_truncdrop_counters()

static void save_truncdrop_counters ( PgStat_TableXactStatus trans,
bool  is_drop 
)
static

Definition at line 959 of file pgstat_relation.c.

960 {
961  if (!trans->truncdropped || is_drop)
962  {
963  trans->inserted_pre_truncdrop = trans->tuples_inserted;
964  trans->updated_pre_truncdrop = trans->tuples_updated;
965  trans->deleted_pre_truncdrop = trans->tuples_deleted;
966  trans->truncdropped = true;
967  }
968 }

References trans.

Referenced by AtEOSubXact_PgStat_Relations(), pgstat_count_truncate(), and pgstat_drop_relation().