From 700a932afdc4787df52e2b30dee7b5bf278f2441 Mon Sep 17 00:00:00 2001
From: Timur Magomedov <t.magomedov@postgrespro.ru>
Date: Fri, 15 Aug 2025 14:53:51 +0300
Subject: [PATCH 3/4] Replaced linear search by switch-case

Switch-case is usually optimized by compilers into optimal
binary search.
---
 contrib/vci/executor/vci_aggmergetranstype.c | 49 +++++++-------------
 1 file changed, 18 insertions(+), 31 deletions(-)

diff --git a/contrib/vci/executor/vci_aggmergetranstype.c b/contrib/vci/executor/vci_aggmergetranstype.c
index 644c5a6fe9c..61a00a6b8da 100644
--- a/contrib/vci/executor/vci_aggmergetranstype.c
+++ b/contrib/vci/executor/vci_aggmergetranstype.c
@@ -38,31 +38,6 @@
 
 #include "postgresql_copy.h"
 
-/**
- * Record information necessary for parallel aggregation for each transition function
- */
-static struct
-{
-	int			transfn_oid;	/* Transition function's funcoid. Array is
-								 * sorted in ascending order */
-}			trans_funcs_table[] = {
-	{F_FLOAT4_ACCUM},	/* 208 */
-	{F_FLOAT8_ACCUM},	/* 222 */
-	{F_INT8INC},	/* 1219 */
-	{F_NUMERIC_ACCUM},	/* 1833 */
-	{F_INT2_ACCUM}, /* 1834 */
-	{F_INT4_ACCUM}, /* 1835 */
-	{F_INT8_ACCUM},	/* 1836 */
-	{F_INT2_SUM}, /* 1840 */
-	{F_INT4_SUM}, /* 1841 */
-	{F_INT2_AVG_ACCUM},	/* 1962 */
-	{F_INT4_AVG_ACCUM},	/* 1963 */
-	{F_INT8_AVG_ACCUM}, /* 2746 */
-	{F_INT8INC_ANY},	/* 2804 */
-	{F_NUMERIC_AVG_ACCUM},	/* 2858 */
-	{F_INTERVAL_AVG_COMBINE}, /* 3325 */
-};
-
 /**
  * Determine if the given aggregation function is a type that can be supported by VCI
  *
@@ -125,15 +100,27 @@ vci_is_supported_aggregation(Aggref *aggref)
 	}
 	else
 	{
-		int			i;
-
-		for (i = 0; i < lengthof(trans_funcs_table); i++)
+		switch (transfn_oid)
 		{
-			if (transfn_oid == trans_funcs_table[i].transfn_oid)
-			{
+			case F_FLOAT4_ACCUM:
+			case F_FLOAT8_ACCUM:
+			case F_INT8INC:
+			case F_NUMERIC_ACCUM:
+			case F_INT2_ACCUM:
+			case F_INT4_ACCUM:
+			case F_INT8_ACCUM:
+			case F_INT2_SUM:
+			case F_INT4_SUM:
+			case F_INT2_AVG_ACCUM:
+			case F_INT4_AVG_ACCUM:
+			case F_INT8_AVG_ACCUM:
+			case F_INT8INC_ANY:
+			case F_NUMERIC_AVG_ACCUM:
+			case F_INTERVAL_AVG_COMBINE:
 				ret = true;
 				break;
-			}
+			default:
+				break;
 		}
 	}
 
-- 
2.43.0

