From 3b00a7a2caef0e0db79267f645effc315559ba7c Mon Sep 17 00:00:00 2001
From: ChangAo Chen <cca5507@qq.com>
Date: Wed, 17 Dec 2025 10:56:49 +0800
Subject: [PATCH v1] Fix unexpected reversal of the list during rehash
 catcache.

We keep the most recently searched tuples at the head of the
list, but there is an unexpected reversal during rehash the
catcache. To fix it, we should use dlist_push_tail() rather
than dlist_push_head().
---
 src/backend/utils/cache/catcache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 1d09c66ac95..0d5c955ca26 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -1013,7 +1013,7 @@ RehashCatCache(CatCache *cp)
 			int			hashIndex = HASH_INDEX(ct->hash_value, newnbuckets);
 
 			dlist_delete(iter.cur);
-			dlist_push_head(&newbucket[hashIndex], &ct->cache_elem);
+			dlist_push_tail(&newbucket[hashIndex], &ct->cache_elem);
 		}
 	}
 
@@ -1051,7 +1051,7 @@ RehashCatCacheLists(CatCache *cp)
 			int			hashIndex = HASH_INDEX(cl->hash_value, newnbuckets);
 
 			dlist_delete(iter.cur);
-			dlist_push_head(&newbucket[hashIndex], &cl->cache_elem);
+			dlist_push_tail(&newbucket[hashIndex], &cl->cache_elem);
 		}
 	}
 
-- 
2.34.1

