From c068e66cb7577aaf7a668b71f17ac95ff35b7736 Mon Sep 17 00:00:00 2001
From: Stepan Neretin <sndcppg@gmail.com>
Date: Sun, 8 Sep 2024 15:43:56 +0700
Subject: [PATCH v2 03/10] Enhanced Sorting Efficiency for Oid Lists

- Replaced `list_sort(result, list_oid_cmp)` with `list_oid_sort(result)` for optimized OID sorting.
- Updated the following files:
  - `src/backend/catalog/heap.c`
  - `src/backend/catalog/pg_publication.c`
  - `src/backend/utils/cache/relcache.c`
---
 src/backend/catalog/heap.c           | 2 +-
 src/backend/catalog/pg_publication.c | 2 +-
 src/backend/utils/cache/relcache.c   | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 01b43cc6a8..368044459a 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -3311,7 +3311,7 @@ restart:
 	list_free(oids);
 
 	/* Now sort and de-duplicate the result list */
-	list_sort(result, list_oid_cmp);
+	list_oid_sort(result);
 	list_deduplicate_oid(result);
 
 	return result;
diff --git a/src/backend/catalog/pg_publication.c b/src/backend/catalog/pg_publication.c
index 7fe5fe2b86..31e1694cfe 100644
--- a/src/backend/catalog/pg_publication.c
+++ b/src/backend/catalog/pg_publication.c
@@ -728,7 +728,7 @@ GetPublicationRelations(Oid pubid, PublicationPartOpt pub_partopt)
 	table_close(pubrelsrel, AccessShareLock);
 
 	/* Now sort and de-duplicate the result list */
-	list_sort(result, list_oid_cmp);
+	list_oid_sort(result);
 	list_deduplicate_oid(result);
 
 	return result;
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 63efc55f09..1220e6ca9a 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -4874,7 +4874,7 @@ RelationGetIndexList(Relation relation)
 	table_close(indrel, AccessShareLock);
 
 	/* Sort the result list into OID order, per API spec. */
-	list_sort(result, list_oid_cmp);
+	list_oid_sort(result);
 
 	/* Now save a copy of the completed list in the relcache entry. */
 	oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
@@ -4966,7 +4966,7 @@ RelationGetStatExtList(Relation relation)
 	table_close(indrel, AccessShareLock);
 
 	/* Sort the result list into OID order, per API spec. */
-	list_sort(result, list_oid_cmp);
+	list_oid_sort(result);
 
 	/* Now save a copy of the completed list in the relcache entry. */
 	oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
-- 
2.43.0

