From a091d578a878cc995ef31dbd405691cce4d998cc Mon Sep 17 00:00:00 2001 From: Zhao Junwang Date: Wed, 13 Sep 2023 14:34:23 +0800 Subject: [PATCH v2] do not refill the hashkey after hash_search It's not necessary to fill the key field for most cases, since hash_search has already done that for you. For developer that using memset to zero the entry structure after enter it, fill the key field is a must, but IMHO that is not good coding style, it's kind of dangerous to touch the key field after the insertion. Signed-off-by: Zhao Junwang --- contrib/dblink/dblink.c | 1 - src/backend/catalog/pg_enum.c | 2 +- src/backend/commands/async.c | 20 ++++++++----------- src/backend/commands/tablecmds.c | 2 +- .../replication/logical/applyparallelworker.c | 2 +- src/backend/replication/logical/relation.c | 1 - 6 files changed, 11 insertions(+), 17 deletions(-) diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index 41e1f6c91d..a50786ccda 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -2562,7 +2562,6 @@ createNewConnection(const char *name, remoteConn *rconn) } hentry->rconn = rconn; - strlcpy(hentry->name, name, sizeof(hentry->name)); } static void diff --git a/src/backend/catalog/pg_enum.c b/src/backend/catalog/pg_enum.c index 3c328664b2..d5b96bdaea 100644 --- a/src/backend/catalog/pg_enum.c +++ b/src/backend/catalog/pg_enum.c @@ -785,6 +785,6 @@ RestoreUncommittedEnums(void *space) init_uncommitted_enums(); do { - hash_search(uncommitted_enums, serialized++, HASH_ENTER, NULL); + (void) hash_search(uncommitted_enums, serialized++, HASH_ENTER, NULL); } while (OidIsValid(*serialized)); } diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index d148d10850..1363c7d842 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -2367,15 +2367,13 @@ AddEventToPendingNotifies(Notification *n) foreach(l, pendingNotifies->events) { Notification *oldn = (Notification *) lfirst(l); - NotificationHash *hentry; bool found; - hentry = (NotificationHash *) hash_search(pendingNotifies->hashtab, - &oldn, - HASH_ENTER, - &found); + (void) hash_search(pendingNotifies->hashtab, + &oldn, + HASH_ENTER, + &found); Assert(!found); - hentry->event = oldn; } } @@ -2385,15 +2383,13 @@ AddEventToPendingNotifies(Notification *n) /* Add event to the hash table if needed */ if (pendingNotifies->hashtab != NULL) { - NotificationHash *hentry; bool found; - hentry = (NotificationHash *) hash_search(pendingNotifies->hashtab, - &n, - HASH_ENTER, - &found); + (void) hash_search(pendingNotifies->hashtab, + &n, + HASH_ENTER, + &found); Assert(!found); - hentry->event = n; } } diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 8a2c671b66..7957771f79 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -2006,7 +2006,7 @@ ExecuteTruncateGuts(List *explicit_rels, ft_info = hash_search(ft_htab, &serverid, HASH_ENTER, &found); if (!found) { - ft_info->serverid = serverid; + Assert(ft_info->serverid == serverid); ft_info->rels = NIL; } diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c index 82f48a488e..08dc76f20e 100644 --- a/src/backend/replication/logical/applyparallelworker.c +++ b/src/backend/replication/logical/applyparallelworker.c @@ -508,8 +508,8 @@ pa_allocate_worker(TransactionId xid) winfo->in_use = true; winfo->serialize_changes = false; + Assert(entry->xid == xid); entry->winfo = winfo; - entry->xid = xid; } /* diff --git a/src/backend/replication/logical/relation.c b/src/backend/replication/logical/relation.c index d62eefed13..a581ac9a4d 100644 --- a/src/backend/replication/logical/relation.c +++ b/src/backend/replication/logical/relation.c @@ -657,7 +657,6 @@ logicalrep_partition_open(LogicalRepRelMapEntry *root, int i; /* Remote relation is copied as-is from the root entry. */ - entry = &part_entry->relmapentry; entry->remoterel.remoteid = remoterel->remoteid; entry->remoterel.nspname = pstrdup(remoterel->nspname); entry->remoterel.relname = pstrdup(remoterel->relname); -- 2.41.0