v2-0001-Add-pg_dump-test-case-for-TOAST-compression.patch

text/x-patch

Filename: v2-0001-Add-pg_dump-test-case-for-TOAST-compression.patch
Type: text/x-patch
Part: 0
Message: Re: Small issues with CREATE TABLE COMPRESSION

Patch

Format: format-patch
Series: patch v2-0001
Subject: Add pg_dump test case for TOAST compression
File+
src/bin/pg_dump/t/002_pg_dump.pl 64 0
From c69ab6dd0fde8e39b7d5aeeb4d74119621c31f58 Mon Sep 17 00:00:00 2001
From: Dilip Kumar <dilipkumar@localhost.localdomain>
Date: Thu, 6 May 2021 21:32:12 +0530
Subject: [PATCH v2 1/2] Add pg_dump test case for TOAST compression

---
 src/bin/pg_dump/t/002_pg_dump.pl | 64 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/src/bin/pg_dump/t/002_pg_dump.pl b/src/bin/pg_dump/t/002_pg_dump.pl
index 86113df..3ea6f10 100644
--- a/src/bin/pg_dump/t/002_pg_dump.pl
+++ b/src/bin/pg_dump/t/002_pg_dump.pl
@@ -374,6 +374,10 @@ my %pgdump_runs = (
 # of the pg_dump runs happening.  This is what "seeds" the
 # system with objects to be dumped out.
 #
+# There is also a flag 'lz4' which can be set if the test case
+# depends upon lz4 library.  And if this flag is set then the
+# test will not be executed if HAVE_LIBLZ4 is not set.
+#
 # Building of this hash takes a bit of time as all of the regexps
 # included in it are compiled.  This greatly improves performance
 # as the regexps are used for each run the test applies to.
@@ -2068,6 +2072,27 @@ my %tests = (
 		unlike => { exclude_dump_test_schema => 1, },
 	},
 
+	'CREATE MATERIALIZED VIEW matview_compression' => {
+		create_order => 20,
+		create_sql   => 'CREATE MATERIALIZED VIEW
+						   dump_test.matview_compression (col2) AS
+					   	   SELECT col2 FROM dump_test.test_table;
+					   	   ALTER MATERIALIZED VIEW dump_test.matview_compression
+					   	   ALTER COLUMN col2 SET COMPRESSION lz4',
+		regexp => qr/^
+			\QCREATE MATERIALIZED VIEW dump_test.matview_compression AS\E
+			\n\s+\QSELECT test_table.col2\E
+			\n\s+\QFROM dump_test.test_table\E
+			\n\s+\QWITH NO DATA;\E
+			.*
+			\QALTER TABLE ONLY dump_test.matview_compression ALTER COLUMN col2 SET COMPRESSION lz4;\E\n
+			/xms,			
+		lz4 => 1,
+		like =>
+		  { %full_runs, %dump_test_schema_runs, section_pre_data => 1, },
+		unlike => { exclude_dump_test_schema => 1, },
+	},
+
 	'CREATE POLICY p1 ON test_table' => {
 		create_order => 22,
 		create_sql   => 'CREATE POLICY p1 ON dump_test.test_table
@@ -2334,6 +2359,26 @@ my %tests = (
 		unlike => { exclude_dump_test_schema => 1, },
 	},
 
+	'CREATE TABLE test_compression' => {
+		create_order => 3,
+		create_sql   => 'CREATE TABLE dump_test.test_compression (
+						   col1 int,
+						   col2 text COMPRESSION lz4
+					   );',
+		regexp => qr/^
+			\QCREATE TABLE dump_test.test_compression (\E\n
+			\s+\Qcol1 integer,\E\n
+			\s+\Qcol2 text\E\n
+			\);\n
+			.*
+			\QALTER TABLE ONLY dump_test.test_compression ALTER COLUMN col2 SET COMPRESSION lz4;\E\n
+			/xms,
+		lz4 => 1,
+		like =>
+		  { %full_runs, %dump_test_schema_runs, section_pre_data => 1, },
+		unlike => { exclude_dump_test_schema => 1, },
+	},
+
 	'CREATE TABLE measurement PARTITIONED BY' => {
 		create_order => 90,
 		create_sql   => 'CREATE TABLE dump_test.measurement (
@@ -3377,6 +3422,7 @@ my $port = $node->port;
 # If it doesn't then we will skip all the COLLATION-related tests.
 my $collation_support = 0;
 my $collation_check_stderr;
+my $supports_lz4 = check_pg_config("#define HAVE_LIBLZ4 1");
 $node->psql(
 	'postgres',
 	"CREATE COLLATION testing FROM \"C\"; DROP COLLATION testing;",
@@ -3445,6 +3491,12 @@ foreach my $run (sort keys %pgdump_runs)
 			next;
 		}
 
+		# Skip any lz4 compression related test
+		if (!$supports_lz4 && defined($tests{$test}->{lz4}))
+		{
+			next;
+		}
+
 		# If there is a like entry, but no unlike entry, then we will test the like case
 		if ($tests{$test}->{like}->{$test_key}
 			&& !defined($tests{$test}->{unlike}->{$test_key}))
@@ -3502,6 +3554,12 @@ foreach my $test (
 			next;
 		}
 
+		# Skip any lz4 compression related test
+		if (!$supports_lz4 && defined($tests{$test}->{lz4}))
+		{
+			next;
+		}
+
 		# Add terminating semicolon
 		$create_sql{$test_db} .= $tests{$test}->{create_sql} . ";";
 	}
@@ -3600,6 +3658,12 @@ foreach my $run (sort keys %pgdump_runs)
 			next;
 		}
 
+		# Skip any lz4 compression related test
+		if (!$supports_lz4 && defined($tests{$test}->{lz4}))
+		{
+			next;
+		}		
+
 		if ($run_db ne $test_db)
 		{
 			next;
-- 
1.8.3.1