From fcc48bee889e4a052ba20f10f08d7f5b5eeaa43f Mon Sep 17 00:00:00 2001
From: "okbob@github.com" <pavel.stehule@gmail.com>
Date: Wed, 29 Nov 2023 07:51:51 +0100
Subject: [PATCH 2/2] fix whitespaces and formatting

---
 contrib/bloom/blscan.c                |  1 +
 contrib/bloom/blutils.c               | 21 +++++---
 src/backend/access/nbtree/nbtsort.c   |  7 +--
 src/backend/commands/explain.c        | 17 ++++---
 src/backend/commands/vacuumparallel.c |  5 +-
 src/backend/executor/execParallel.c   |  5 +-
 src/backend/executor/instrument.c     | 72 ++++++++++++++++-----------
 7 files changed, 79 insertions(+), 49 deletions(-)

diff --git a/contrib/bloom/blscan.c b/contrib/bloom/blscan.c
index 8890951943..7fc43f174d 100644
--- a/contrib/bloom/blscan.c
+++ b/contrib/bloom/blscan.c
@@ -167,5 +167,6 @@ blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
 	}
 	FreeAccessStrategy(bas);
 	bloomUsage.matches += ntids;
+
 	return ntids;
 }
diff --git a/contrib/bloom/blutils.c b/contrib/bloom/blutils.c
index d8fff4f057..1ba7afc607 100644
--- a/contrib/bloom/blutils.c
+++ b/contrib/bloom/blutils.c
@@ -38,19 +38,23 @@ PG_FUNCTION_INFO_V1(blhandler);
 BloomUsage bloomUsage;
 
 static void
-bloomUsageAdd(CustomResourceUsage* dst, CustomResourceUsage const* add)
+bloomUsageAdd(CustomResourceUsage *dst,
+			  CustomResourceUsage const *add)
 {
-	((BloomUsage*)dst)->matches += ((BloomUsage*)add)->matches;
+	((BloomUsage*) dst)->matches += ((BloomUsage*) add)->matches;
 }
 
 static void
-bloomUsageAccum(CustomResourceUsage* acc, CustomResourceUsage const* end, CustomResourceUsage const* start)
+bloomUsageAccum(CustomResourceUsage* acc,
+				CustomResourceUsage const *end,
+				CustomResourceUsage const *start)
 {
-	((BloomUsage*)acc)->matches += ((BloomUsage*)end)->matches - ((BloomUsage*)start)->matches;;
+	((BloomUsage*) acc)->matches +=
+		  ((BloomUsage*) end)->matches - ((BloomUsage*) start)->matches;
 }
 
 static void
-bloomUsageShow(ExplainState* es, CustomResourceUsage const* usage, bool planning)
+bloomUsageShow(ExplainState *es, CustomResourceUsage const *usage, bool planning)
 {
 	if (es->format == EXPLAIN_FORMAT_TEXT)
 	{
@@ -60,18 +64,20 @@ bloomUsageShow(ExplainState* es, CustomResourceUsage const* usage, bool planning
 			appendStringInfoString(es->str, "Planning:\n");
 			es->indent++;
 		}
+
 		ExplainIndentText(es);
 		appendStringInfoString(es->str, "Bloom:");
 		appendStringInfo(es->str, " matches=%lld",
-						 (long long) ((BloomUsage*)usage)->matches);
+						 (long long) ((BloomUsage*) usage)->matches);
 		appendStringInfoChar(es->str, '\n');
+
 		if (planning)
 			es->indent--;
 	}
 	else
 	{
 		ExplainPropertyInteger("Bloom Matches", NULL,
-							   ((BloomUsage*)usage)->matches, es);
+							   ((BloomUsage*) usage)->matches, es);
 	}
 }
 
@@ -128,6 +134,7 @@ _PG_init(void)
 		bl_relopt_tab[i + 1].opttype = RELOPT_TYPE_INT;
 		bl_relopt_tab[i + 1].offset = offsetof(BloomOptions, bitSize[0]) + sizeof(int) * i;
 	}
+
 	RegisterCustomInsrumentation(&bloomInstr);
 }
 
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index a4ab0d6ba0..e9dc1190af 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -1635,7 +1635,6 @@ _bt_begin_parallel(BTBuildState *buildstate, bool isconcurrent, int request)
 								 mul_size(pgCustUsageSize, pcxt->nworkers));
 	shm_toc_insert(pcxt->toc, PARALLEL_KEY_CUST_USAGE, custusage);
 
-
 	/* Launch workers, saving status for leader/caller */
 	LaunchParallelWorkers(pcxt);
 	btleader->pcxt = pcxt;
@@ -1687,7 +1686,9 @@ _bt_end_parallel(BTLeader *btleader)
 	 * or we might get incomplete data.)
 	 */
 	for (i = 0; i < btleader->pcxt->nworkers_launched; i++)
-		InstrAccumParallelQuery(&btleader->bufferusage[i], &btleader->walusage[i], btleader->custusage + pgCustUsageSize*i);
+		InstrAccumParallelQuery(&btleader->bufferusage[i],
+								&btleader->walusage[i],
+								btleader->custusage + pgCustUsageSize * i);
 
 	/* Free last reference to MVCC snapshot, if one was used */
 	if (IsMVCCSnapshot(btleader->snapshot))
@@ -1906,7 +1907,7 @@ _bt_parallel_build_main(dsm_segment *seg, shm_toc *toc)
 	custusage = shm_toc_lookup(toc, PARALLEL_KEY_CUST_USAGE, false);
 	InstrEndParallelQuery(&bufferusage[ParallelWorkerNumber],
 						  &walusage[ParallelWorkerNumber],
-						  custusage + ParallelWorkerNumber*pgCustUsageSize);
+						  custusage + ParallelWorkerNumber * pgCustUsageSize);
 
 #ifdef BTREE_BUILD_STATS
 	if (log_btree_build_stats)
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index d3dc19f3ce..a5dc8451f5 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -226,9 +226,11 @@ ExplainQuery(ParseState *pstate, ExplainStmt *stmt,
 		else
 		{
 			bool found = false;
+
 			foreach (c, pgCustInstr)
 			{
-				CustomInstrumentation *ci = (CustomInstrumentation*)lfirst(c);
+				CustomInstrumentation *ci = (CustomInstrumentation*) lfirst(c);
+
 				if (strcmp(opt->defname, ci->name) == 0)
 				{
 					ci->selected = true;
@@ -339,7 +341,7 @@ ExplainState *
 NewExplainState(void)
 {
 	ExplainState *es = (ExplainState *) palloc0(sizeof(ExplainState));
-	ListCell* lc;
+	ListCell   *lc;
 
 	/* Set default options (most fields can be left as zeroes). */
 	es->costs = true;
@@ -349,7 +351,8 @@ NewExplainState(void)
 	/* Reset custom instrumentations selection flag */
 	foreach (lc, pgCustInstr)
 	{
-		CustomInstrumentation *ci = (CustomInstrumentation*)lfirst(lc);
+		CustomInstrumentation *ci = (CustomInstrumentation*) lfirst(lc);
+
 		ci->selected = false;
 	}
 	return es;
@@ -3598,15 +3601,17 @@ explain_get_index_name(Oid indexId)
  * Show select custom usage details
  */
 static void
-show_custom_usage(ExplainState *es, const char* usage, bool planning)
+show_custom_usage(ExplainState *es, const char *usage, bool planning)
 {
-	ListCell* lc;
+	ListCell   *lc;
 
 	foreach (lc, pgCustInstr)
 	{
-		CustomInstrumentation *ci = (CustomInstrumentation*)lfirst(lc);
+		CustomInstrumentation *ci = (CustomInstrumentation*) lfirst(lc);
+
 		if (ci->selected)
 			ci->show(es, usage, planning);
+
 		usage += ci->size;
 	}
 }
diff --git a/src/backend/commands/vacuumparallel.c b/src/backend/commands/vacuumparallel.c
index 299782b2f7..5afb31d145 100644
--- a/src/backend/commands/vacuumparallel.c
+++ b/src/backend/commands/vacuumparallel.c
@@ -411,7 +411,7 @@ parallel_vacuum_init(Relation rel, Relation *indrels, int nindexes,
 								 mul_size(sizeof(WalUsage), pcxt->nworkers));
 	shm_toc_insert(pcxt->toc, PARALLEL_VACUUM_KEY_WAL_USAGE, wal_usage);
 	pvs->wal_usage = wal_usage;
-    custom_usage = shm_toc_allocate(pcxt->toc,
+	custom_usage = shm_toc_allocate(pcxt->toc,
 									mul_size(pgCustUsageSize, pcxt->nworkers));
 	shm_toc_insert(pcxt->toc, PARALLEL_VACUUM_KEY_CUSTOM_USAGE, custom_usage);
 	pvs->custom_usage = custom_usage;
@@ -718,7 +718,8 @@ parallel_vacuum_process_all_indexes(ParallelVacuumState *pvs, int num_index_scan
 		WaitForParallelWorkersToFinish(pvs->pcxt);
 
 		for (int i = 0; i < pvs->pcxt->nworkers_launched; i++)
-			InstrAccumParallelQuery(&pvs->buffer_usage[i], &pvs->wal_usage[i], pvs->custom_usage + pgCustUsageSize*i);
+			InstrAccumParallelQuery(&pvs->buffer_usage[i], &pvs->wal_usage[i],
+									pvs->custom_usage + pgCustUsageSize * i);
 	}
 
 	/*
diff --git a/src/backend/executor/execParallel.c b/src/backend/executor/execParallel.c
index 39d9754a0f..cba8fe7795 100644
--- a/src/backend/executor/execParallel.c
+++ b/src/backend/executor/execParallel.c
@@ -1178,7 +1178,8 @@ ExecParallelFinish(ParallelExecutorInfo *pei)
 	 * finish, or we might get incomplete data.)
 	 */
 	for (i = 0; i < nworkers; i++)
-		InstrAccumParallelQuery(&pei->buffer_usage[i], &pei->wal_usage[i], pei->custom_usage + pgCustUsageSize*i);
+		InstrAccumParallelQuery(&pei->buffer_usage[i], &pei->wal_usage[i],
+								pei->custom_usage + pgCustUsageSize * i);
 
 	pei->finished = true;
 }
@@ -1411,7 +1412,7 @@ ParallelQueryMain(dsm_segment *seg, shm_toc *toc)
 	FixedParallelExecutorState *fpes;
 	BufferUsage *buffer_usage;
 	WalUsage   *wal_usage;
-	char *custom_usage; 
+	char *custom_usage;
 	DestReceiver *receiver;
 	QueryDesc  *queryDesc;
 	SharedExecutorInstrumentation *instrumentation;
diff --git a/src/backend/executor/instrument.c b/src/backend/executor/instrument.c
index ca3e7eff74..d37b783616 100644
--- a/src/backend/executor/instrument.c
+++ b/src/backend/executor/instrument.c
@@ -23,33 +23,36 @@ static BufferUsage save_pgBufferUsage;
 WalUsage	pgWalUsage;
 static WalUsage save_pgWalUsage;
 
-List* pgCustInstr; /* description of custom instriumentations */
+List *pgCustInstr; /* description of custom instriumentations */
 Size pgCustUsageSize;
 static CustomInstrumentationData save_pgCustUsage; /* saved custom instrumentation state */
 
-
 static void BufferUsageAdd(BufferUsage *dst, const BufferUsage *add);
 static void WalUsageAdd(WalUsage *dst, WalUsage *add);
 
 void
-RegisterCustomInsrumentation(CustomInstrumentation* inst)
+RegisterCustomInsrumentation(CustomInstrumentation *inst)
 {
 	MemoryContext oldcontext = MemoryContextSwitchTo(TopMemoryContext);
+
 	pgCustInstr = lappend(pgCustInstr, inst);
 	pgCustUsageSize += inst->size;
 	MemoryContextSwitchTo(oldcontext);
+
 	if (pgCustUsageSize > MAX_CUSTOM_INSTR_SIZE)
-		elog(ERROR, "Total size of custom instrumentations exceed limit %d",  MAX_CUSTOM_INSTR_SIZE);
+		elog(ERROR, "Total size of custom instrumentations exceed limit %d",
+			 MAX_CUSTOM_INSTR_SIZE);
 }
 
 void
-GetCustomInstrumentationState(char* dst)
+GetCustomInstrumentationState(char *dst)
 {
-	ListCell* lc;
+	ListCell   *lc;
 
 	foreach (lc, pgCustInstr)
 	{
-		CustomInstrumentation *ci = (CustomInstrumentation*)lfirst(lc);	
+		CustomInstrumentation *ci = (CustomInstrumentation*) lfirst(lc);
+
 		memcpy(dst, ci->usage, ci->size);
 		dst += ci->size;
 	}
@@ -58,16 +61,18 @@ GetCustomInstrumentationState(char* dst)
 void
 AccumulateCustomInstrumentationState(char* dst, char const* before)
 {
-	ListCell* lc;
+	ListCell   *lc;
 
 	foreach (lc, pgCustInstr)
 	{
-		CustomInstrumentation *ci = (CustomInstrumentation*)lfirst(lc);	
+		CustomInstrumentation *ci = (CustomInstrumentation*) lfirst(lc);
+
 		if (ci->selected)
 		{
 			memset(dst, 0, ci->size);
 			ci->accum(dst, ci->usage, before);
 		}
+
 		dst += ci->size;
 		before += ci->size;
 	}
@@ -96,6 +101,7 @@ InstrAlloc(int n, int instrument_options, bool async_mode)
 			instr[i].async_mode = async_mode;
 		}
 	}
+
 	return instr;
 }
 
@@ -113,8 +119,9 @@ InstrInit(Instrumentation *instr, int instrument_options)
 void
 InstrStartNode(Instrumentation *instr)
 {
-	ListCell *lc;
-	char* cust_start = instr->cust_usage_start.data;
+	ListCell   *lc;
+	char	   *cust_start = instr->cust_usage_start.data;
+
 	if (instr->need_timer &&
 		!INSTR_TIME_SET_CURRENT_LAZY(instr->starttime))
 		elog(ERROR, "InstrStartNode called twice in a row");
@@ -128,7 +135,8 @@ InstrStartNode(Instrumentation *instr)
 
 	foreach (lc, pgCustInstr)
 	{
-		CustomInstrumentation *ci = (CustomInstrumentation*)lfirst(lc);
+		CustomInstrumentation *ci = (CustomInstrumentation*) lfirst(lc);
+
 		memcpy(cust_start, ci->usage, ci->size);
 		cust_start += ci->size;
 	}
@@ -140,9 +148,9 @@ InstrStopNode(Instrumentation *instr, double nTuples)
 {
 	double		save_tuplecount = instr->tuplecount;
 	instr_time	endtime;
-	ListCell *lc;
-	char *cust_start = instr->cust_usage_start.data;
-	char *cust_usage = instr->cust_usage.data;
+	ListCell  *lc;
+	char	   *cust_start = instr->cust_usage_start.data;
+	char	   *cust_usage = instr->cust_usage.data;
 
 	/* count the returned tuples */
 	instr->tuplecount += nTuples;
@@ -170,13 +178,14 @@ InstrStopNode(Instrumentation *instr, double nTuples)
 
 	foreach (lc, pgCustInstr)
 	{
-		CustomInstrumentation *ci = (CustomInstrumentation*)lfirst(lc);
+		CustomInstrumentation *ci = (CustomInstrumentation*) lfirst(lc);
+
 		ci->accum(cust_usage, ci->usage, cust_start);
 		cust_start += ci->size;
 		cust_usage += ci->size;
 	}
 
-    /* Is this the first tuple of this cycle? */
+	/* Is this the first tuple of this cycle? */
 	if (!instr->running)
 	{
 		instr->running = true;
@@ -234,9 +243,9 @@ InstrEndLoop(Instrumentation *instr)
 void
 InstrAggNode(Instrumentation *dst, Instrumentation *add)
 {
-	ListCell *lc;
-	char *cust_dst = dst->cust_usage.data;
-	char *cust_add = add->cust_usage.data;
+	ListCell   *lc;
+	char	   *cust_dst = dst->cust_usage.data;
+	char	   *cust_add = add->cust_usage.data;
 
 	if (!dst->running && add->running)
 	{
@@ -266,7 +275,8 @@ InstrAggNode(Instrumentation *dst, Instrumentation *add)
 
 	foreach (lc, pgCustInstr)
 	{
-		CustomInstrumentation *ci = (CustomInstrumentation*)lfirst(lc);
+		CustomInstrumentation *ci = (CustomInstrumentation*) lfirst(lc);
+
 		ci->add(cust_dst, cust_add);
 		cust_dst += ci->size;
 		cust_add += ci->size;
@@ -277,15 +287,16 @@ InstrAggNode(Instrumentation *dst, Instrumentation *add)
 void
 InstrStartParallelQuery(void)
 {
-	ListCell* lc;
-	char* cust_dst = save_pgCustUsage.data;
+	ListCell   *lc;
+	char	   *cust_dst = save_pgCustUsage.data;
 
 	save_pgBufferUsage = pgBufferUsage;
 	save_pgWalUsage = pgWalUsage;
 
 	foreach (lc, pgCustInstr)
 	{
-		CustomInstrumentation *ci = (CustomInstrumentation*)lfirst(lc);
+		CustomInstrumentation *ci = (CustomInstrumentation*) lfirst(lc);
+
 		memcpy(cust_dst, ci->usage, ci->size);
 		cust_dst += ci->size;
 	}
@@ -295,8 +306,8 @@ InstrStartParallelQuery(void)
 void
 InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage, char* cust_usage)
 {
-	ListCell *lc;
-	char* cust_save = save_pgCustUsage.data;
+	ListCell   *lc;
+	char	   *cust_save = save_pgCustUsage.data;
 
 	memset(bufusage, 0, sizeof(BufferUsage));
 	BufferUsageAccumDiff(bufusage, &pgBufferUsage, &save_pgBufferUsage);
@@ -305,7 +316,8 @@ InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage, char* cust_usag
 
 	foreach (lc, pgCustInstr)
 	{
-		CustomInstrumentation *ci = (CustomInstrumentation*)lfirst(lc);
+		CustomInstrumentation *ci = (CustomInstrumentation*) lfirst(lc);
+
 		ci->accum(cust_usage, ci->usage, cust_save);
 		cust_usage += ci->size;
 		cust_save += ci->size;
@@ -316,13 +328,15 @@ InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage, char* cust_usag
 void
 InstrAccumParallelQuery(BufferUsage *bufusage, WalUsage *walusage, char* cust_usage)
 {
-	ListCell *lc;
+	ListCell   *lc;
+
 	BufferUsageAdd(&pgBufferUsage, bufusage);
 	WalUsageAdd(&pgWalUsage, walusage);
 
 	foreach (lc, pgCustInstr)
 	{
-		CustomInstrumentation *ci = (CustomInstrumentation*)lfirst(lc);
+		CustomInstrumentation *ci = (CustomInstrumentation*) lfirst(lc);
+
 		ci->add(ci->usage, cust_usage);
 		cust_usage += ci->size;
 	}
-- 
2.43.0

