On Mon, Aug 26, 2024 at 09:32:54AM +0300, Heikki Linnakangas wrote: > Currently, we rely on the fact that all the xl_xact_* structs require > sizeof(int) alignment. See comment above struct xl_xact_xinfo.
Thanks, I have missed this part. So that explains the alignment I'd better use in the record. > One idea is to store the uint64 as two uint32's. Nice, we could just do that. This idea makes me feel much better than sticking more aligment macros in the paths where the record is built. Attached is an updated patch doing that. ubsan is silent with that. -- Michael
From 89e6d4342bbfa90e900263b7594d1147247e19e2 Mon Sep 17 00:00:00 2001 From: Michael Paquier <mich...@paquier.xyz> Date: Thu, 29 Aug 2024 08:48:54 +0900 Subject: [PATCH v2] Bump PgStat_HashKey.objoid to be 8 bytes XXX: Catalog version bump! XXX: XLOG_PAGE_MAGIC bump! --- src/include/access/xact.h | 8 +++- 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 | 7 +++- 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 | 33 ++++++++------- 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, 95 insertions(+), 72 deletions(-) diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 6d4439f052..fb64d7413a 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -283,7 +283,13 @@ typedef struct xl_xact_stats_item { int kind; Oid dboid; - Oid objoid; + + /* + * This stores the value of PgStat_HashKey.objid as two uint32 as all the + * fields of xl_xact_xinfo should be multiples of size(int). + */ + uint32 objid_lo; + uint32 objid_hi; } 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..889cb955c1 100644 --- a/src/backend/access/rmgrdesc/xactdesc.c +++ b/src/backend/access/rmgrdesc/xactdesc.c @@ -319,10 +319,13 @@ xact_desc_stats(StringInfo buf, const char *label, appendStringInfo(buf, "; %sdropped stats:", label); for (i = 0; i < ndropped; i++) { - appendStringInfo(buf, " %d/%u/%u", + uint64 objid = + ((uint64) dropped_stats[i].objid_hi) << 32 | dropped_stats[i].objid_lo; + + appendStringInfo(buf, " %d/%u/%llu", dropped_stats[i].kind, dropped_stats[i].dboid, - dropped_stats[i].objoid); + (unsigned long long) 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..f87a195996 100644 --- a/src/backend/utils/activity/pgstat_xact.c +++ b/src/backend/utils/activity/pgstat_xact.c @@ -77,6 +77,7 @@ AtEOXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, bool isCommit) PgStat_PendingDroppedStatsItem *pending = dclist_container(PgStat_PendingDroppedStatsItem, node, iter.cur); xl_xact_stats_item *it = &pending->item; + uint64 objid = ((uint64) it->objid_hi) << 32 | it->objid_lo; if (isCommit && !pending->is_create) { @@ -84,7 +85,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, objid)) not_freed_count++; } else if (!isCommit && pending->is_create) @@ -93,7 +94,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, objid)) not_freed_count++; } @@ -149,6 +150,7 @@ AtEOSubXact_PgStat_DroppedStats(PgStat_SubXactStatus *xact_state, PgStat_PendingDroppedStatsItem *pending = dclist_container(PgStat_PendingDroppedStatsItem, node, iter.cur); xl_xact_stats_item *it = &pending->item; + uint64 objid = ((uint64) it->objid_hi) << 32 | it->objid_lo; dclist_delete_from(&xact_state->pending_drops, &pending->node); @@ -158,7 +160,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, objid)) not_freed_count++; pfree(pending); } @@ -319,8 +321,9 @@ pgstat_execute_transactional_drops(int ndrops, struct xl_xact_stats_item *items, for (int i = 0; i < ndrops; i++) { xl_xact_stats_item *it = &items[i]; + uint64 objid = ((uint64) it->objid_hi) << 32 | it->objid_lo; - if (!pgstat_drop_entry(it->kind, it->dboid, it->objoid)) + if (!pgstat_drop_entry(it->kind, it->dboid, objid)) not_freed_count++; } @@ -329,7 +332,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 +344,8 @@ 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_lo = (uint32) objid; + drop->item.objid_hi = (uint32) (objid >> 32); dclist_push_tail(&xact_state->pending_drops, &drop->node); } @@ -354,18 +358,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 +381,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