static bool have_function_stats = false;
/*
- * Tuple insertion/deletion counts for an open transaction can't be propagated
- * into PgStat_TableStatus counters until we know if it is going to commit
- * or abort. Hence, we keep these counts in per-subxact structs that live
- * in TopTransactionContext. This data structure is designed on the assumption
- * that subxacts won't usually modify very many tables.
+ * Some stats changes are transactional. To maintain those, a stack of
+ * PgStat_SubXactStatus entries is maintained, which contain data pertaining
+ * to the current transaction and its active subtransactions.
*/
typedef struct PgStat_SubXactStatus
{
int nest_level; /* subtransaction nest level */
+
struct PgStat_SubXactStatus *prev; /* higher-level subxact if any */
+
+ /*
+ * Tuple insertion/deletion counts for an open transaction can't be
+ * propagated into PgStat_TableStatus counters until we know if it is
+ * going to commit or abort. Hence, we keep these counts in per-subxact
+ * structs that live in TopTransactionContext. This data structure is
+ * designed on the assumption that subxacts won't usually modify very many
+ * tables.
+ */
PgStat_TableXactStatus *first; /* head of list for this subxact */
} PgStat_SubXactStatus;
}
/*
- * get_tabstat_stack_level - add a new (sub)transaction stack entry if needed
+ * Ensure (sub)transaction stack entry for the given nest_level exists, adding
+ * it if needed.
*/
static PgStat_SubXactStatus *
-get_tabstat_stack_level(int nest_level)
+pgstat_xact_stack_level_get(int nest_level)
{
PgStat_SubXactStatus *xact_state;
* If this is the first rel to be modified at the current nest level, we
* first have to push a transaction stack entry.
*/
- xact_state = get_tabstat_stack_level(nest_level);
+ xact_state = pgstat_xact_stack_level_get(nest_level);
/* Now make a per-table stack entry */
trans = (PgStat_TableXactStatus *)
pgstat_info->trans = trans;
}
+/*
+ * Add a new (sub)transaction record if needed.
+ */
+static void
+ensure_tabstat_xact_level(PgStat_TableStatus *pgstat_info)
+{
+ int nest_level = GetCurrentTransactionNestLevel();
+
+ if (pgstat_info->trans == NULL ||
+ pgstat_info->trans->nest_level != nest_level)
+ add_tabstat_xact_level(pgstat_info, nest_level);
+}
+
/*
* pgstat_count_heap_insert - count a tuple insertion of n tuples
*/
if (pgstat_relation_should_count(rel))
{
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
- int nest_level = GetCurrentTransactionNestLevel();
-
- /* We have to log the effect at the proper transactional level */
- if (pgstat_info->trans == NULL ||
- pgstat_info->trans->nest_level != nest_level)
- add_tabstat_xact_level(pgstat_info, nest_level);
+ ensure_tabstat_xact_level(pgstat_info);
pgstat_info->trans->tuples_inserted += n;
}
}
if (pgstat_relation_should_count(rel))
{
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
- int nest_level = GetCurrentTransactionNestLevel();
-
- /* We have to log the effect at the proper transactional level */
- if (pgstat_info->trans == NULL ||
- pgstat_info->trans->nest_level != nest_level)
- add_tabstat_xact_level(pgstat_info, nest_level);
+ ensure_tabstat_xact_level(pgstat_info);
pgstat_info->trans->tuples_updated++;
/* t_tuples_hot_updated is nontransactional, so just advance it */
if (pgstat_relation_should_count(rel))
{
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
- int nest_level = GetCurrentTransactionNestLevel();
-
- /* We have to log the effect at the proper transactional level */
- if (pgstat_info->trans == NULL ||
- pgstat_info->trans->nest_level != nest_level)
- add_tabstat_xact_level(pgstat_info, nest_level);
+ ensure_tabstat_xact_level(pgstat_info);
pgstat_info->trans->tuples_deleted++;
}
}
if (pgstat_relation_should_count(rel))
{
PgStat_TableStatus *pgstat_info = rel->pgstat_info;
- int nest_level = GetCurrentTransactionNestLevel();
-
- /* We have to log the effect at the proper transactional level */
- if (pgstat_info->trans == NULL ||
- pgstat_info->trans->nest_level != nest_level)
- add_tabstat_xact_level(pgstat_info, nest_level);
+ ensure_tabstat_xact_level(pgstat_info);
pgstat_truncdrop_save_counters(pgstat_info->trans, false);
pgstat_info->trans->tuples_inserted = 0;
pgstat_info->trans->tuples_updated = 0;
*/
PgStat_SubXactStatus *upper_xact_state;
- upper_xact_state = get_tabstat_stack_level(nestDepth - 1);
+ upper_xact_state = pgstat_xact_stack_level_get(nestDepth - 1);
trans->next = upper_xact_state->first;
upper_xact_state->first = trans;
trans->nest_level = nestDepth - 1;