Extend PgStat_HashKey.objid from 4 to 8 bytes
authorMichael Paquier <[email protected]>
Wed, 18 Sep 2024 03:44:15 +0000 (12:44 +0900)
committerMichael Paquier <[email protected]>
Wed, 18 Sep 2024 03:44:15 +0000 (12:44 +0900)
This opens the possibility to define keys for more types of statistics
kinds in PgStat_HashKey, the first case being 8-byte query IDs for
statistics like pg_stat_statements.

This increases the size of PgStat_HashKey from 12 to 16 bytes, while
PgStatShared_HashEntry, entry stored in the dshash for pgstats, keeps
the same size due to alignment.

xl_xact_stats_item, that tracks the stats items to drop in commit WAL
records, is increased from 12 to 16 bytes.  Note that individual chunks
in commit WAL records should be multiples of sizeof(int), hence 8-byte
object IDs are stored as two uint32, based on a suggestion from Heikki
Linnakangas.

While on it, the field of PgStat_HashKey is renamed from "objoid" to
"objid", as for some stats kinds this field does not refer to OIDs but
just IDs, like for replication slot stats.

This commit bumps the following format variables:
- PGSTAT_FILE_FORMAT_ID, as PgStat_HashKey is written to the stats file
for non-serialized stats kinds in the dshash table.
- XLOG_PAGE_MAGIC for the changes in xl_xact_stats_item.
- Catalog version, for the SQL function pg_stat_have_stats().

Reviewed-by: Bertrand Drouvot
Discussion: https://postgr.es/m/[email protected]

17 files changed:
src/backend/access/rmgrdesc/xactdesc.c
src/backend/catalog/system_functions.sql
src/backend/utils/activity/pgstat.c
src/backend/utils/activity/pgstat_replslot.c
src/backend/utils/activity/pgstat_shmem.c
src/backend/utils/activity/pgstat_xact.c
src/backend/utils/adt/pgstatfuncs.c
src/include/access/xact.h
src/include/access/xlog_internal.h
src/include/catalog/catversion.h
src/include/catalog/pg_proc.dat
src/include/pgstat.h
src/include/utils/pgstat_internal.h
src/test/modules/injection_points/injection_stats.c
src/test/recovery/t/029_stats_restart.pl
src/test/regress/expected/stats.out
src/test/regress/sql/stats.sql

index dccca201e05c0c7a1a437d7cae0a6fbb8bba5cb5..889cb955c1886c76e05826eae316b51130291e96 100644 (file)
@@ -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);
        }
    }
 }
index 623b9539b1554543d206fdac91f6880d1e53b81a..b0d0de051e7f06b56275d58ae1d6decbedc20b20 100644 (file)
@@ -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;
 
index a7f2dfc744cfca68bdcdde13f639108b3a0a91d0..d1768a89f6e52205c6931f34720896589782f4d0 100644 (file)
@@ -846,7 +846,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();
@@ -855,7 +855,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);
@@ -926,7 +926,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;
@@ -941,7 +941,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)
@@ -967,7 +967,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)
    {
@@ -1036,13 +1036,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;
 }
 
 /*
@@ -1257,7 +1257,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;
 
@@ -1272,7 +1272,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)
@@ -1295,11 +1295,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;
@@ -1648,8 +1648,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;
        }
 
@@ -1885,8 +1886,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;
                        }
                    }
@@ -1957,8 +1959,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;
                    }
 
@@ -1969,8 +1972,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;
                    }
 
index da11b867445955fefcf851a10203705be8d73ed5..ddf2ab9928d6dd39cc57587c9d80c67bce123f5c 100644 (file)
@@ -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;
 }
index ec93bf6902f46d7e3b6018fa91b0a3eb18b3c481..a09c6fee055e55ba73945b9e4474af60ce8a491d 100644 (file)
@@ -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;
 
index 1877d22f146bcec2ceaf26c917d111bac7ded7c8..f87a195996a8ff80a574641616b7f17d62e89ec3 100644 (file)
@@ -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);
 }
index 33c7b25560b4e702fa20292ba4818a3bd16c8fb1..9c23ac7c8c8cdeae40e0d70f948f6b0277f5a541 100644 (file)
@@ -2046,8 +2046,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));
 }
index 6d4439f0524ee8fad7160b4d672b0eb198643e18..fb64d7413a2c08cbff2c1f064d7b6e821e41a73b 100644 (file)
@@ -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
index e5cdba0584a01aff36ca0af2b987d3a487b8afb3..5ef244bcdb44156967a9a04e268230c512a20f2c 100644 (file)
@@ -31,7 +31,7 @@
 /*
  * Each page of XLOG file has a header like this:
  */
-#define XLOG_PAGE_MAGIC 0xD116 /* can be used as WAL version indicator */
+#define XLOG_PAGE_MAGIC 0xD117 /* can be used as WAL version indicator */
 
 typedef struct XLogPageHeaderData
 {
index fe92cdd632f3ce6731ecfb21635be011f948e043..1d54ef6edceff92991516b0a789b6985fc0097ab 100644 (file)
@@ -57,6 +57,6 @@
  */
 
 /*                         yyyymmddN */
-#define CATALOG_VERSION_NO 202409172
+#define CATALOG_VERSION_NO 202409181
 
 #endif
index 2513c36fcbf35ec6f61a5177558c4b13ec88e0ef..43f608d7a0a0cf994034d3f293112ea1ee2a44d2 100644 (file)
 
 { 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',
index be2c91168a1b6ef8efdc78270d34b7487abca4ce..4752dfe7197a65a3533aa393d72ae9f54afa20fc 100644 (file)
@@ -267,7 +267,7 @@ typedef struct PgStat_TableXactStatus
  * ------------------------------------------------------------
  */
 
-#define PGSTAT_FILE_FORMAT_ID  0x01A5BCAE
+#define PGSTAT_FILE_FORMAT_ID  0x01A5BCAF
 
 typedef struct PgStat_ArchiverStats
 {
@@ -511,7 +511,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 */
@@ -520,7 +520,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);
 
 
 /*
index bba90e898dd353e5b1ac550085a5636034cb7b7b..61b2e1f96b259e3572d3e93d8f879ffb5da4b93e 100644 (file)
@@ -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;
 
 /*
@@ -563,10 +564,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);
 
 
@@ -660,16 +664,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,
@@ -718,8 +722,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);
 
 
 /*
index 582686a0a83b4ae0f65c0cc9fecbfe98dea4d025..d89d0559134fab259a29248060ab6c71b417326a 100644 (file)
@@ -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.
index 93a7209f69aacfd5b453831016cfeec6cbb4f20a..d14ac124181322659ed897a34b8bf85f1bcb753c 100644 (file)
@@ -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
index 6e08898b183063e026ebb690e224874f5e108020..56771f83edffbf1c96f6c0e2f80b28e644d1ca06 100644 (file)
@@ -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 
 --------------------
index d8ac0d06f484d6023e3eb22c499a21a3aa1ba7a5..7147cc2f8957033d6fe4cb58d3a8a483784ba907 100644 (file)
@@ -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);