Hi all, While working more on the cumulative pgstats and its interactions with pg_stat_statements, one thing that I have been annoyed with is that the dshash key for variable-numbered stats uses a pair of (Oid dboid, Oid objoid), mostly to stick with the fact that most of the stats are dealing with system objects.
That's not completely true, though, as statistics can also implement their own index numbering without storing these numbers to disk, by defining {from,to}_serialized_name. Replication slots do that, so we are already considering as OIDs numbers that are not that. For pg_stat_statements, one issue with the current pgstats is that we want to use the query ID as hash key, which is 8 bytes, while also having some knowledge of the database OID because we want to be able to clean up stats entries about specific databases. Please find attached a patch switching PgStat_HashKey.objoid from an Oid to uint64 to be able to handle cases of stats that want more space. The size of PgStat_HashKey is increased from 12 to 16 bytes, but with alignment the size of PgStatShared_HashEntry (what's stored in the dshash) is unchanged at 32 bytes. Perhaps what's proposed here is a bad idea for a good reason, and we could just leave with storing 4 bytes of the query ID in the dshash instead of 8. Anyway, we make a lot of efforts to use 8 bytes to reduce conflicts with different statements. Another thing to note is the change for xl_xact_stats_item, requiring a bump of XLOG_PAGE_MAGIC. A second thing is pg_stat_have_stats that needs to use a different argument than an OID for the object, requiring a catversion bump. An interesting thing is that I have seen ubsan complain about this patch, due to the way WAL records xl_xact_commit are built with XACT_XINFO_HAS_DROPPED_STATS and parsed as xl_xact_stats_item requires an 8-byte alignment now (see pg_waldump TAP reports when using the attached), but we don't enforce anything as the data of such WAL records is added with a simple XLogRegisterData(), like: # xactdesc.c:91:28: runtime error: member access within misaligned address 0x5651e996b86c for type 'struct xl_xact_stats_items', which requires 8 byte alignment # 0x5651e996b86c: note: pointer points here TBH, I've looked at that for quite a bit, thinking about the addition of some "dummy" member to some of the parsed structures to force some padding, or play with the alignment macros, or for some alignment when inserting the record, or looked at pg_attribute_aligned(). First I'm surprised that it did not show up as an issue yet in this area. Second, I could not get down to something "nice", but perhaps there are preferred approaches when it comes to that and somebody has a fancier idea? Or perhaps the problem is bigger than that due to the way the record is designed and built? It also feels that I'm missing something obvious, not sure what TBH. Still I'm OK to paint some more MAXALIGN()s to make sure that all these deparsing pointers have a correct alignment with some more TYPEALIGN()s or similar, because this deparsing stuff is about that, but I'm also wondering if there is an argument for forcing that for the record itself? I'll think more about that next week or so. Anyway, I'm attaching that to the next CF for discussion for now, as there could be objections about this whole idea, as well. Thoughts or comments? -- Michael
From a33ded084b9855e00a588963bd24ed2a453bdd03 Mon Sep 17 00:00:00 2001 From: Michael Paquier <mich...@paquier.xyz> Date: Mon, 26 Aug 2024 08:19:22 +0900 Subject: [PATCH] Bump PgStat_HashKey.objoid to be 8 bytes XXX: Catalog version bump! XXX: XLOG_PAGE_MAGIC bump! --- src/include/access/xact.h | 2 +- src/include/catalog/pg_proc.dat | 2 +- src/include/pgstat.h | 4 +- src/include/utils/pgstat_internal.h | 24 ++++++----- src/backend/access/rmgrdesc/xactdesc.c | 4 +- src/backend/catalog/system_functions.sql | 2 +- src/backend/utils/activity/pgstat.c | 42 ++++++++++--------- src/backend/utils/activity/pgstat_replslot.c | 8 ++-- src/backend/utils/activity/pgstat_shmem.c | 21 +++++----- src/backend/utils/activity/pgstat_xact.c | 29 ++++++------- src/backend/utils/adt/pgstatfuncs.c | 4 +- .../injection_points/injection_stats.c | 4 +- src/test/recovery/t/029_stats_restart.pl | 4 +- src/test/regress/expected/stats.out | 2 +- src/test/regress/sql/stats.sql | 2 +- 15 files changed, 82 insertions(+), 72 deletions(-) diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 6d4439f052..3dd91b3304 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -283,7 +283,7 @@ typedef struct xl_xact_stats_item { int kind; Oid dboid; - Oid objoid; + uint64 objid; } xl_xact_stats_item; typedef struct xl_xact_stats_items diff --git a/src/include/catalog/pg_proc.dat b/src/include/catalog/pg_proc.dat index 4abc6d9526..494c5c28a0 100644 --- a/src/include/catalog/pg_proc.dat +++ b/src/include/catalog/pg_proc.dat @@ -5532,7 +5532,7 @@ { oid => '6230', descr => 'statistics: check if a stats object exists', proname => 'pg_stat_have_stats', provolatile => 'v', proparallel => 'r', - prorettype => 'bool', proargtypes => 'text oid oid', + prorettype => 'bool', proargtypes => 'text oid int8', prosrc => 'pg_stat_have_stats' }, { oid => '6231', descr => 'statistics: information about subscription stats', diff --git a/src/include/pgstat.h b/src/include/pgstat.h index f63159c55c..7d79533c37 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -508,7 +508,7 @@ extern long pgstat_report_stat(bool force); extern void pgstat_force_next_flush(void); extern void pgstat_reset_counters(void); -extern void pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid); +extern void pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid); extern void pgstat_reset_of_kind(PgStat_Kind kind); /* stats accessors */ @@ -517,7 +517,7 @@ extern TimestampTz pgstat_get_stat_snapshot_timestamp(bool *have_snapshot); /* helpers */ extern PgStat_Kind pgstat_get_kind_from_str(char *kind_str); -extern bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid); +extern bool pgstat_have_entry(PgStat_Kind kind, Oid dboid, uint64 objid); /* diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat_internal.h index fb132e439d..d6249e4df5 100644 --- a/src/include/utils/pgstat_internal.h +++ b/src/include/utils/pgstat_internal.h @@ -53,7 +53,8 @@ typedef struct PgStat_HashKey { PgStat_Kind kind; /* statistics entry kind */ Oid dboid; /* database ID. InvalidOid for shared objects. */ - Oid objoid; /* object ID, either table or function. */ + uint64 objid; /* object ID (table, function, etc.), or + * identifier. */ } PgStat_HashKey; /* @@ -544,10 +545,13 @@ extern void pgstat_assert_is_up(void); #endif extern void pgstat_delete_pending_entry(PgStat_EntryRef *entry_ref); -extern PgStat_EntryRef *pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid, bool *created_entry); -extern PgStat_EntryRef *pgstat_fetch_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid); +extern PgStat_EntryRef *pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, + uint64 objid, + bool *created_entry); +extern PgStat_EntryRef *pgstat_fetch_pending_entry(PgStat_Kind kind, + Oid dboid, uint64 objid); -extern void *pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid); +extern void *pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid); extern void pgstat_snapshot_fixed(PgStat_Kind kind); @@ -638,16 +642,16 @@ extern bool pgstat_replslot_from_serialized_name_cb(const NameData *name, PgStat extern void pgstat_attach_shmem(void); extern void pgstat_detach_shmem(void); -extern PgStat_EntryRef *pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, Oid objoid, +extern PgStat_EntryRef *pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, uint64 objid, bool create, bool *created_entry); extern bool pgstat_lock_entry(PgStat_EntryRef *entry_ref, bool nowait); extern bool pgstat_lock_entry_shared(PgStat_EntryRef *entry_ref, bool nowait); extern void pgstat_unlock_entry(PgStat_EntryRef *entry_ref); -extern bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid); +extern bool pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid); extern void pgstat_drop_all_entries(void); -extern PgStat_EntryRef *pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, Oid objoid, +extern PgStat_EntryRef *pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait); -extern void pgstat_reset_entry(PgStat_Kind kind, Oid dboid, Oid objoid, TimestampTz ts); +extern void pgstat_reset_entry(PgStat_Kind kind, Oid dboid, uint64 objid, TimestampTz ts); extern void pgstat_reset_entries_of_kind(PgStat_Kind kind, TimestampTz ts); extern void pgstat_reset_matching_entries(bool (*do_reset) (PgStatShared_HashEntry *, Datum), Datum match_data, @@ -694,8 +698,8 @@ extern void pgstat_subscription_reset_timestamp_cb(PgStatShared_Common *header, */ extern PgStat_SubXactStatus *pgstat_get_xact_stack_level(int nest_level); -extern void pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, Oid objoid); -extern void pgstat_create_transactional(PgStat_Kind kind, Oid dboid, Oid objoid); +extern void pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, uint64 objid); +extern void pgstat_create_transactional(PgStat_Kind kind, Oid dboid, uint64 objid); /* diff --git a/src/backend/access/rmgrdesc/xactdesc.c b/src/backend/access/rmgrdesc/xactdesc.c index dccca201e0..389d8c27d4 100644 --- a/src/backend/access/rmgrdesc/xactdesc.c +++ b/src/backend/access/rmgrdesc/xactdesc.c @@ -319,10 +319,10 @@ xact_desc_stats(StringInfo buf, const char *label, appendStringInfo(buf, "; %sdropped stats:", label); for (i = 0; i < ndropped; i++) { - appendStringInfo(buf, " %d/%u/%u", + appendStringInfo(buf, " %d/%u/%llu", dropped_stats[i].kind, dropped_stats[i].dboid, - dropped_stats[i].objoid); + (unsigned long long) dropped_stats[i].objid); } } } diff --git a/src/backend/catalog/system_functions.sql b/src/backend/catalog/system_functions.sql index 623b9539b1..b0d0de051e 100644 --- a/src/backend/catalog/system_functions.sql +++ b/src/backend/catalog/system_functions.sql @@ -684,7 +684,7 @@ REVOKE EXECUTE ON FUNCTION pg_stat_reset_single_function_counters(oid) FROM publ REVOKE EXECUTE ON FUNCTION pg_stat_reset_replication_slot(text) FROM public; -REVOKE EXECUTE ON FUNCTION pg_stat_have_stats(text, oid, oid) FROM public; +REVOKE EXECUTE ON FUNCTION pg_stat_have_stats(text, oid, int8) FROM public; REVOKE EXECUTE ON FUNCTION pg_stat_reset_subscription_stats(oid) FROM public; diff --git a/src/backend/utils/activity/pgstat.c b/src/backend/utils/activity/pgstat.c index b2ca3f39b7..825ab7ff07 100644 --- a/src/backend/utils/activity/pgstat.c +++ b/src/backend/utils/activity/pgstat.c @@ -797,7 +797,7 @@ pgstat_reset_counters(void) * GRANT system. */ void -pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid) +pgstat_reset(PgStat_Kind kind, Oid dboid, uint64 objid) { const PgStat_KindInfo *kind_info = pgstat_get_kind_info(kind); TimestampTz ts = GetCurrentTimestamp(); @@ -806,7 +806,7 @@ pgstat_reset(PgStat_Kind kind, Oid dboid, Oid objoid) Assert(!pgstat_get_kind_info(kind)->fixed_amount); /* reset the "single counter" */ - pgstat_reset_entry(kind, dboid, objoid, ts); + pgstat_reset_entry(kind, dboid, objid, ts); if (!kind_info->accessed_across_databases) pgstat_reset_database_timestamp(dboid, ts); @@ -877,7 +877,7 @@ pgstat_clear_snapshot(void) } void * -pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid) +pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, uint64 objid) { PgStat_HashKey key; PgStat_EntryRef *entry_ref; @@ -892,7 +892,7 @@ pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid) key.kind = kind; key.dboid = dboid; - key.objoid = objoid; + key.objid = objid; /* if we need to build a full snapshot, do so */ if (pgstat_fetch_consistency == PGSTAT_FETCH_CONSISTENCY_SNAPSHOT) @@ -918,7 +918,7 @@ pgstat_fetch_entry(PgStat_Kind kind, Oid dboid, Oid objoid) pgStatLocal.snapshot.mode = pgstat_fetch_consistency; - entry_ref = pgstat_get_entry_ref(kind, dboid, objoid, false, NULL); + entry_ref = pgstat_get_entry_ref(kind, dboid, objid, false, NULL); if (entry_ref == NULL || entry_ref->shared_entry->dropped) { @@ -987,13 +987,13 @@ pgstat_get_stat_snapshot_timestamp(bool *have_snapshot) } bool -pgstat_have_entry(PgStat_Kind kind, Oid dboid, Oid objoid) +pgstat_have_entry(PgStat_Kind kind, Oid dboid, uint64 objid) { /* fixed-numbered stats always exist */ if (pgstat_get_kind_info(kind)->fixed_amount) return true; - return pgstat_get_entry_ref(kind, dboid, objoid, false, NULL) != NULL; + return pgstat_get_entry_ref(kind, dboid, objid, false, NULL) != NULL; } /* @@ -1208,7 +1208,7 @@ pgstat_build_snapshot_fixed(PgStat_Kind kind) * created, false otherwise. */ PgStat_EntryRef * -pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid, bool *created_entry) +pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid, bool *created_entry) { PgStat_EntryRef *entry_ref; @@ -1223,7 +1223,7 @@ pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid, bool *created ALLOCSET_SMALL_SIZES); } - entry_ref = pgstat_get_entry_ref(kind, dboid, objoid, + entry_ref = pgstat_get_entry_ref(kind, dboid, objid, true, created_entry); if (entry_ref->pending == NULL) @@ -1246,11 +1246,11 @@ pgstat_prep_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid, bool *created * that it shouldn't be needed. */ PgStat_EntryRef * -pgstat_fetch_pending_entry(PgStat_Kind kind, Oid dboid, Oid objoid) +pgstat_fetch_pending_entry(PgStat_Kind kind, Oid dboid, uint64 objid) { PgStat_EntryRef *entry_ref; - entry_ref = pgstat_get_entry_ref(kind, dboid, objoid, false, NULL); + entry_ref = pgstat_get_entry_ref(kind, dboid, objid, false, NULL); if (entry_ref == NULL || entry_ref->pending == NULL) return NULL; @@ -1599,8 +1599,9 @@ pgstat_write_statsfile(XLogRecPtr redo) */ if (!pgstat_is_kind_valid(ps->key.kind)) { - elog(WARNING, "found unknown stats entry %u/%u/%u", - ps->key.kind, ps->key.dboid, ps->key.objoid); + elog(WARNING, "found unknown stats entry %u/%u/%llu", + ps->key.kind, ps->key.dboid, + (unsigned long long) ps->key.objid); continue; } @@ -1830,8 +1831,9 @@ pgstat_read_statsfile(XLogRecPtr redo) if (!pgstat_is_kind_valid(key.kind)) { - elog(WARNING, "invalid stats kind for entry %u/%u/%u of type %c", - key.kind, key.dboid, key.objoid, t); + elog(WARNING, "invalid stats kind for entry %u/%u/%llu of type %c", + key.kind, key.dboid, + (unsigned long long) key.objid, t); goto error; } } @@ -1896,8 +1898,9 @@ pgstat_read_statsfile(XLogRecPtr redo) if (found) { dshash_release_lock(pgStatLocal.shared_hash, p); - elog(WARNING, "found duplicate stats entry %u/%u/%u of type %c", - key.kind, key.dboid, key.objoid, t); + elog(WARNING, "found duplicate stats entry %u/%u/%llu of type %c", + key.kind, key.dboid, + (unsigned long long) key.objid, t); goto error; } @@ -1908,8 +1911,9 @@ pgstat_read_statsfile(XLogRecPtr redo) pgstat_get_entry_data(key.kind, header), pgstat_get_entry_len(key.kind))) { - elog(WARNING, "could not read data for entry %u/%u/%u of type %c", - key.kind, key.dboid, key.objoid, t); + elog(WARNING, "could not read data for entry %u/%u/%llu of type %c", + key.kind, key.dboid, + (unsigned long long) key.objid, t); goto error; } diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c index da11b86744..ddf2ab9928 100644 --- a/src/backend/utils/activity/pgstat_replslot.c +++ b/src/backend/utils/activity/pgstat_replslot.c @@ -193,9 +193,9 @@ pgstat_replslot_to_serialized_name_cb(const PgStat_HashKey *key, const PgStatSha * isn't allowed to change at this point, we can assume that a slot exists * at the offset. */ - if (!ReplicationSlotName(key->objoid, name)) - elog(ERROR, "could not find name for replication slot index %u", - key->objoid); + if (!ReplicationSlotName(key->objid, name)) + elog(ERROR, "could not find name for replication slot index %llu", + (unsigned long long) key->objid); } bool @@ -209,7 +209,7 @@ pgstat_replslot_from_serialized_name_cb(const NameData *name, PgStat_HashKey *ke key->kind = PGSTAT_KIND_REPLSLOT; key->dboid = InvalidOid; - key->objoid = idx; + key->objid = idx; return true; } diff --git a/src/backend/utils/activity/pgstat_shmem.c b/src/backend/utils/activity/pgstat_shmem.c index ec93bf6902..a09c6fee05 100644 --- a/src/backend/utils/activity/pgstat_shmem.c +++ b/src/backend/utils/activity/pgstat_shmem.c @@ -429,10 +429,10 @@ pgstat_get_entry_ref_cached(PgStat_HashKey key, PgStat_EntryRef **entry_ref_p) * if the entry is newly created, false otherwise. */ PgStat_EntryRef * -pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, Oid objoid, bool create, +pgstat_get_entry_ref(PgStat_Kind kind, Oid dboid, uint64 objid, bool create, bool *created_entry) { - PgStat_HashKey key = {.kind = kind,.dboid = dboid,.objoid = objoid}; + PgStat_HashKey key = {.kind = kind,.dboid = dboid,.objid = objid}; PgStatShared_HashEntry *shhashent; PgStatShared_Common *shheader = NULL; PgStat_EntryRef *entry_ref; @@ -644,13 +644,13 @@ pgstat_unlock_entry(PgStat_EntryRef *entry_ref) * Helper function to fetch and lock shared stats. */ PgStat_EntryRef * -pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, Oid objoid, +pgstat_get_entry_ref_locked(PgStat_Kind kind, Oid dboid, uint64 objid, bool nowait) { PgStat_EntryRef *entry_ref; /* find shared table stats entry corresponding to the local entry */ - entry_ref = pgstat_get_entry_ref(kind, dboid, objoid, true, NULL); + entry_ref = pgstat_get_entry_ref(kind, dboid, objid, true, NULL); /* lock the shared entry to protect the content, skip if failed */ if (!pgstat_lock_entry(entry_ref, nowait)) @@ -820,9 +820,10 @@ pgstat_drop_entry_internal(PgStatShared_HashEntry *shent, */ if (shent->dropped) elog(ERROR, - "trying to drop stats entry already dropped: kind=%s dboid=%u objoid=%u refcount=%u", + "trying to drop stats entry already dropped: kind=%s dboid=%u objid=%llu refcount=%u", pgstat_get_kind_info(shent->key.kind)->name, - shent->key.dboid, shent->key.objoid, + shent->key.dboid, + (unsigned long long) shent->key.objid, pg_atomic_read_u32(&shent->refcount)); shent->dropped = true; @@ -905,9 +906,9 @@ pgstat_drop_database_and_contents(Oid dboid) * pgstat_gc_entry_refs(). */ bool -pgstat_drop_entry(PgStat_Kind kind, Oid dboid, Oid objoid) +pgstat_drop_entry(PgStat_Kind kind, Oid dboid, uint64 objid) { - PgStat_HashKey key = {.kind = kind,.dboid = dboid,.objoid = objoid}; + PgStat_HashKey key = {.kind = kind,.dboid = dboid,.objid = objid}; PgStatShared_HashEntry *shent; bool freed = true; @@ -980,13 +981,13 @@ shared_stat_reset_contents(PgStat_Kind kind, PgStatShared_Common *header, * Reset one variable-numbered stats entry. */ void -pgstat_reset_entry(PgStat_Kind kind, Oid dboid, Oid objoid, TimestampTz ts) +pgstat_reset_entry(PgStat_Kind kind, Oid dboid, uint64 objid, TimestampTz ts) { PgStat_EntryRef *entry_ref; Assert(!pgstat_get_kind_info(kind)->fixed_amount); - entry_ref = pgstat_get_entry_ref(kind, dboid, objoid, false, NULL); + entry_ref = pgstat_get_entry_ref(kind, dboid, objid, false, NULL); if (!entry_ref || entry_ref->shared_entry->dropped) return; diff --git a/src/backend/utils/activity/pgstat_xact.c b/src/backend/utils/activity/pgstat_xact.c index 1877d22f14..7c864f07d2 100644 --- a/src/backend/utils/activity/pgstat_xact.c +++ b/src/backend/utils/activity/pgstat_xact.c @@ -84,7 +84,7 @@ AtEOXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, bool isCommit) * Transaction that dropped an object committed. Drop the stats * too. */ - if (!pgstat_drop_entry(it->kind, it->dboid, it->objoid)) + if (!pgstat_drop_entry(it->kind, it->dboid, it->objid)) not_freed_count++; } else if (!isCommit && pending->is_create) @@ -93,7 +93,7 @@ AtEOXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, bool isCommit) * Transaction that created an object aborted. Drop the stats * associated with the object. */ - if (!pgstat_drop_entry(it->kind, it->dboid, it->objoid)) + if (!pgstat_drop_entry(it->kind, it->dboid, it->objid)) not_freed_count++; } @@ -158,7 +158,7 @@ AtEOSubXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, * Subtransaction creating a new stats object aborted. Drop the * stats object. */ - if (!pgstat_drop_entry(it->kind, it->dboid, it->objoid)) + if (!pgstat_drop_entry(it->kind, it->dboid, it->objid)) not_freed_count++; pfree(pending); } @@ -320,7 +320,7 @@ pgstat_execute_transactional_drops(int ndrops, struct xl_xact_stats_item *items, { xl_xact_stats_item *it = &items[i]; - if (!pgstat_drop_entry(it->kind, it->dboid, it->objoid)) + if (!pgstat_drop_entry(it->kind, it->dboid, it->objid)) not_freed_count++; } @@ -329,7 +329,7 @@ pgstat_execute_transactional_drops(int ndrops, struct xl_xact_stats_item *items, } static void -create_drop_transactional_internal(PgStat_Kind kind, Oid dboid, Oid objoid, bool is_create) +create_drop_transactional_internal(PgStat_Kind kind, Oid dboid, uint64 objid, bool is_create) { int nest_level = GetCurrentTransactionNestLevel(); PgStat_SubXactStatus *xact_state; @@ -341,7 +341,7 @@ create_drop_transactional_internal(PgStat_Kind kind, Oid dboid, Oid objoid, bool drop->is_create = is_create; drop->item.kind = kind; drop->item.dboid = dboid; - drop->item.objoid = objoid; + drop->item.objid = objid; dclist_push_tail(&xact_state->pending_drops, &drop->node); } @@ -354,18 +354,19 @@ create_drop_transactional_internal(PgStat_Kind kind, Oid dboid, Oid objoid, bool * dropped. */ void -pgstat_create_transactional(PgStat_Kind kind, Oid dboid, Oid objoid) +pgstat_create_transactional(PgStat_Kind kind, Oid dboid, uint64 objid) { - if (pgstat_get_entry_ref(kind, dboid, objoid, false, NULL)) + if (pgstat_get_entry_ref(kind, dboid, objid, false, NULL)) { ereport(WARNING, - errmsg("resetting existing statistics for kind %s, db=%u, oid=%u", - (pgstat_get_kind_info(kind))->name, dboid, objoid)); + errmsg("resetting existing statistics for kind %s, db=%u, oid=%llu", + (pgstat_get_kind_info(kind))->name, dboid, + (unsigned long long) objid)); - pgstat_reset(kind, dboid, objoid); + pgstat_reset(kind, dboid, objid); } - create_drop_transactional_internal(kind, dboid, objoid, /* create */ true); + create_drop_transactional_internal(kind, dboid, objid, /* create */ true); } /* @@ -376,7 +377,7 @@ pgstat_create_transactional(PgStat_Kind kind, Oid dboid, Oid objoid) * alive. */ void -pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, Oid objoid) +pgstat_drop_transactional(PgStat_Kind kind, Oid dboid, uint64 objid) { - create_drop_transactional_internal(kind, dboid, objoid, /* create */ false); + create_drop_transactional_internal(kind, dboid, objid, /* create */ false); } diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index 3221137123..883efebc27 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -2027,8 +2027,8 @@ pg_stat_have_stats(PG_FUNCTION_ARGS) { char *stats_type = text_to_cstring(PG_GETARG_TEXT_P(0)); Oid dboid = PG_GETARG_OID(1); - Oid objoid = PG_GETARG_OID(2); + uint64 objid = PG_GETARG_INT64(2); PgStat_Kind kind = pgstat_get_kind_from_str(stats_type); - PG_RETURN_BOOL(pgstat_have_entry(kind, dboid, objoid)); + PG_RETURN_BOOL(pgstat_have_entry(kind, dboid, objid)); } diff --git a/src/test/modules/injection_points/injection_stats.c b/src/test/modules/injection_points/injection_stats.c index 582686a0a8..d89d055913 100644 --- a/src/test/modules/injection_points/injection_stats.c +++ b/src/test/modules/injection_points/injection_stats.c @@ -51,9 +51,9 @@ static const PgStat_KindInfo injection_stats = { }; /* - * Compute stats entry idx from point name with a 4-byte hash. + * Compute stats entry idx from point name with an 8-byte hash. */ -#define PGSTAT_INJ_IDX(name) hash_bytes((const unsigned char *) name, strlen(name)) +#define PGSTAT_INJ_IDX(name) hash_bytes_extended((const unsigned char *) name, strlen(name), 0) /* * Kind ID reserved for statistics of injection points. diff --git a/src/test/recovery/t/029_stats_restart.pl b/src/test/recovery/t/029_stats_restart.pl index 93a7209f69..d14ac12418 100644 --- a/src/test/recovery/t/029_stats_restart.pl +++ b/src/test/recovery/t/029_stats_restart.pl @@ -292,10 +292,10 @@ sub trigger_funcrel_stat sub have_stats { - my ($kind, $dboid, $objoid) = @_; + my ($kind, $dboid, $objid) = @_; return $node->safe_psql($connect_db, - "SELECT pg_stat_have_stats('$kind', $dboid, $objoid)"); + "SELECT pg_stat_have_stats('$kind', $dboid, $objid)"); } sub overwrite_file diff --git a/src/test/regress/expected/stats.out b/src/test/regress/expected/stats.out index 6e08898b18..56771f83ed 100644 --- a/src/test/regress/expected/stats.out +++ b/src/test/regress/expected/stats.out @@ -1120,7 +1120,7 @@ SELECT pg_stat_have_stats('bgwriter', 0, 0); -- unknown stats kinds error out SELECT pg_stat_have_stats('zaphod', 0, 0); ERROR: invalid statistics kind: "zaphod" --- db stats have objoid 0 +-- db stats have objid 0 SELECT pg_stat_have_stats('database', :dboid, 1); pg_stat_have_stats -------------------- diff --git a/src/test/regress/sql/stats.sql b/src/test/regress/sql/stats.sql index d8ac0d06f4..7147cc2f89 100644 --- a/src/test/regress/sql/stats.sql +++ b/src/test/regress/sql/stats.sql @@ -542,7 +542,7 @@ ROLLBACK; SELECT pg_stat_have_stats('bgwriter', 0, 0); -- unknown stats kinds error out SELECT pg_stat_have_stats('zaphod', 0, 0); --- db stats have objoid 0 +-- db stats have objid 0 SELECT pg_stat_have_stats('database', :dboid, 1); SELECT pg_stat_have_stats('database', :dboid, 0); -- 2.45.2
signature.asc
Description: PGP signature