diff --git a/src/backend/utils/adt/mcxtfuncs.c b/src/backend/utils/adt/mcxtfuncs.c
index 199e68c1ae..5905958c1f 100644
--- a/src/backend/utils/adt/mcxtfuncs.c
+++ b/src/backend/utils/adt/mcxtfuncs.c
@@ -55,7 +55,7 @@ get_memory_context_name_and_ident(MemoryContext context, const char **const name
 	 * To be consistent with logging output, we label dynahash contexts with
 	 * just the hash table name as with MemoryContextStatsPrint().
 	 */
-	if (ident && strcmp(*name, "dynahash") == 0)
+	if (*ident == NULL && strcmp(*name, "dynahash") == 0)
 	{
 		*name = *ident;
 		*ident = NULL;