Subject: index_delete_sort: Unnecessary variable "low" is used in heapam.c

From: btnakamurakoukil <[email-masked]>
Date: Tue, 24 Sep 2024 17:32:48 +0900

Hi hackers,

I noticed unnecessary variable "low" in index_delete_sort() 
(/postgres/src/backend/access/heap/heapam.c), patch attached. What do 
you think?

Regards,
Koki Nakamura <[email-masked]>

From c0bf7f8468cb0e4f74c41e434adf70bdbfb3ad6d Mon Sep 17 00:00:00 2001
From: KokiNaka <[email-masked]>
Date: Tue, 24 Sep 2024 10:46:09 +0900
Subject: [PATCH] Delete low

---
 src/backend/access/heap/heapam.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index f167107257..64953541cd 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -7940,7 +7940,6 @@ index_delete_sort(TM_IndexDeleteOp *delstate)
 {
 	TM_IndexDelete *deltids = delstate->deltids;
 	int			ndeltids = delstate->ndeltids;
-	int			low = 0;
 
 	/*
 	 * Shellsort gap sequence (taken from Sedgewick-Incerpi paper).
@@ -7956,7 +7955,7 @@ index_delete_sort(TM_IndexDeleteOp *delstate)
 
 	for (int g = 0; g < lengthof(gaps); g++)
 	{
-		for (int hi = gaps[g], i = low + hi; i < ndeltids; i++)
+		for (int hi = gaps[g], i = hi; i < ndeltids; i++)
 		{
 			TM_IndexDelete d = deltids[i];
 			int			j = i;
-- 
2.40.1

---

From: Daniel Gustafsson <[email-masked]>
Date: Tue, 24 Sep 2024 14:31:30 +0200

> On 24 Sep 2024, at 10:32, btnakamurakoukil <[email-masked]> wrote:

> I noticed unnecessary variable "low" in index_delete_sort() (/postgres/src/backend/access/heap/heapam.c), patch attached. What do you think?

That variable does indeed seem to not be used, and hasn't been used since it
was committed in d168b666823.  The question is if it's a left-over from
development which can be removed, or if it should be set and we're missing an
optimization.  Having not read the referenced paper I can't tell so adding
Peter Geoghegan who wrote this for clarification.

--
Daniel Gustafsson