From 707f406252e2b38699677081bd0da9bf5a19b04e Mon Sep 17 00:00:00 2001
From: usernamedt <usernamedt@yandex-team.com>
Date: Wed, 12 Jan 2022 23:14:02 +0500
Subject: [PATCH 3/4] Turn on zlib compression for CI test runs

---
 src/backend/utils/misc/guc_tables.c |  2 +-
 src/common/zpq_stream.c             | 11 +++++------
 src/interfaces/libpq/fe-connect.c   |  2 +-
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index bef045e5be9..e1e5cab63af 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -4453,7 +4453,7 @@ struct config_string ConfigureNamesString[] =
 			NULL
 		},
 		&libpq_compress_algorithms,
-		"off",
+		"zlib",
 		check_libpq_compression, NULL, NULL
 	},
 
diff --git a/src/common/zpq_stream.c b/src/common/zpq_stream.c
index a712200e453..9bdb3527072 100644
--- a/src/common/zpq_stream.c
+++ b/src/common/zpq_stream.c
@@ -156,9 +156,11 @@ zpq_build_msg_compression_map(ZpqStream * zpq)
 
 	for (i = 0; i < 256; i++)
 	{
-		zpq->compressor_by_msg_type[i] = -1;
+		/* Compress all messages during the CI test runs */
+		zpq->compressor_by_msg_type[i] = 0;
 	}
 
+	// XXX why is this looping around compressors and overwriting the same bytes??
 	for (i = 0; i < zpq->n_compressors; i++)
 	{
 		/* compress CopyData, DataRow and Query messages */
@@ -186,11 +188,8 @@ zpq_build_msg_compression_map(ZpqStream * zpq)
 static inline int
 zpq_choose_compressor(ZpqStream * zpq, char msg_type, uint32 msg_len)
 {
-	if (msg_len >= ZPQ_COMPRESS_THRESHOLD)
-	{
-		return zpq->compressor_by_msg_type[(unsigned char) msg_type];
-	}
-	return -1;
+    /* Compress messages with any length during the CI test runs */
+    return zpq->compressor_by_msg_type[(unsigned char) msg_type];
 }
 
 /*
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index c50f9ac602c..f8f831f6665 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -337,7 +337,7 @@ static const internalPQconninfoOption PQconninfoOptions[] = {
 		"Replication", "D", 5,
 	offsetof(struct pg_conn, replication)},
 
-	{"compression", "PGCOMPRESSION", "off", NULL,
+	{"compression", "PGCOMPRESSION", "zlib", NULL,
 		"Libpq-compression", "", 16,
 	offsetof(struct pg_conn, compression)},
 
-- 
2.25.1

