github.com/tuhaihe/gpbackup@v1.0.3/integration/postdata_create_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"database/sql"
     5  	"strings"
     6  
     7  	"github.com/tuhaihe/gp-common-go-libs/structmatcher"
     8  	"github.com/tuhaihe/gp-common-go-libs/testhelper"
     9  	"github.com/tuhaihe/gpbackup/backup"
    10  	"github.com/tuhaihe/gpbackup/testutils"
    11  
    12  	. "github.com/onsi/ginkgo/v2"
    13  	. "github.com/onsi/gomega"
    14  )
    15  
    16  var _ = Describe("backup integration create statement tests", func() {
    17  	BeforeEach(func() {
    18  		tocfile, backupfile = testutils.InitializeTestTOC(buffer, "predata")
    19  	})
    20  	Describe("PrintCreateIndexStatements", func() {
    21  		var (
    22  			indexMetadataMap backup.MetadataMap
    23  			index            backup.IndexDefinition
    24  		)
    25  		BeforeEach(func() {
    26  			indexMetadataMap = backup.MetadataMap{}
    27  			index = backup.IndexDefinition{
    28  				Oid:          0,
    29  				Name:         "index1",
    30  				OwningSchema: "public",
    31  				OwningTable:  "testtable",
    32  				Def:          sql.NullString{String: "CREATE INDEX index1 ON public.testtable USING btree (i)", Valid: true},
    33  			}
    34  		})
    35  		It("creates a basic index", func() {
    36  			indexes := []backup.IndexDefinition{{Oid: 0, Name: "index1", OwningSchema: "public", OwningTable: "testtable", Def: sql.NullString{String: "CREATE INDEX index1 ON public.testtable USING btree (i)", Valid: true}}}
    37  			backup.PrintCreateIndexStatements(backupfile, tocfile, indexes, indexMetadataMap)
    38  
    39  			//Create table whose columns we can index
    40  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.testtable(i int)")
    41  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.testtable")
    42  
    43  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
    44  
    45  			resultIndexes := backup.GetIndexes(connectionPool)
    46  			Expect(resultIndexes).To(HaveLen(1))
    47  			structmatcher.ExpectStructsToMatchExcluding(&resultIndexes[0], &indexes[0], "Oid")
    48  		})
    49  		It("creates an index used for clustering", func() {
    50  			indexes := []backup.IndexDefinition{{Oid: 0, Name: "index1", OwningSchema: "public", OwningTable: "testtable", Def: sql.NullString{String: "CREATE INDEX index1 ON public.testtable USING btree (i)", Valid: true}, IsClustered: true}}
    51  			backup.PrintCreateIndexStatements(backupfile, tocfile, indexes, indexMetadataMap)
    52  
    53  			//Create table whose columns we can index
    54  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.testtable(i int)")
    55  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.testtable")
    56  
    57  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
    58  
    59  			resultIndexes := backup.GetIndexes(connectionPool)
    60  			Expect(resultIndexes).To(HaveLen(1))
    61  			structmatcher.ExpectStructsToMatchExcluding(&resultIndexes[0], &indexes[0], "Oid")
    62  		})
    63  		It("creates an index with a comment", func() {
    64  			indexes := []backup.IndexDefinition{{Oid: 1, Name: "index1", OwningSchema: "public", OwningTable: "testtable", Def: sql.NullString{String: "CREATE INDEX index1 ON public.testtable USING btree (i)", Valid: true}}}
    65  			indexMetadataMap = testutils.DefaultMetadataMap("INDEX", false, false, true, false)
    66  			indexMetadata := indexMetadataMap[indexes[0].GetUniqueID()]
    67  			backup.PrintCreateIndexStatements(backupfile, tocfile, indexes, indexMetadataMap)
    68  
    69  			//Create table whose columns we can index
    70  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.testtable(i int)")
    71  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.testtable")
    72  
    73  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
    74  
    75  			resultIndexes := backup.GetIndexes(connectionPool)
    76  			resultMetadataMap := backup.GetCommentsForObjectType(connectionPool, backup.TYPE_INDEX)
    77  			resultMetadata := resultMetadataMap[resultIndexes[0].GetUniqueID()]
    78  			Expect(resultIndexes).To(HaveLen(1))
    79  			structmatcher.ExpectStructsToMatchExcluding(&resultIndexes[0], &indexes[0], "Oid")
    80  			structmatcher.ExpectStructsToMatch(&resultMetadata, &indexMetadata)
    81  		})
    82  		It("creates an index in a non-default tablespace", func() {
    83  			if false {
    84  				testhelper.AssertQueryRuns(connectionPool, "CREATE TABLESPACE test_tablespace FILESPACE test_dir")
    85  			} else {
    86  				testhelper.AssertQueryRuns(connectionPool, "CREATE TABLESPACE test_tablespace LOCATION '/tmp/test_dir'")
    87  			}
    88  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLESPACE test_tablespace")
    89  			indexes := []backup.IndexDefinition{{Oid: 0, Name: "index1", OwningSchema: "public", OwningTable: "testtable", Tablespace: "test_tablespace", Def: sql.NullString{String: "CREATE INDEX index1 ON public.testtable USING btree (i)", Valid: true}}}
    90  			backup.PrintCreateIndexStatements(backupfile, tocfile, indexes, indexMetadataMap)
    91  
    92  			//Create table whose columns we can index
    93  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.testtable(i int)")
    94  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.testtable")
    95  
    96  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
    97  
    98  			resultIndexes := backup.GetIndexes(connectionPool)
    99  			Expect(resultIndexes).To(HaveLen(1))
   100  			structmatcher.ExpectStructsToMatchExcluding(&resultIndexes[0], &indexes[0], "Oid")
   101  		})
   102  		It("creates a unique index used as replica identity", func() {
   103  			testutils.SkipIfBefore6(connectionPool)
   104  			index.Def = sql.NullString{String: "CREATE UNIQUE INDEX index1 ON public.testtable USING btree (i)", Valid: true}
   105  			index.IsReplicaIdentity = true
   106  			indexes := []backup.IndexDefinition{index}
   107  			backup.PrintCreateIndexStatements(backupfile, tocfile, indexes, indexMetadataMap)
   108  
   109  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.testtable(i int NOT NULL)")
   110  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.testtable")
   111  
   112  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   113  
   114  			resultIndexes := backup.GetIndexes(connectionPool)
   115  			Expect(resultIndexes).To(HaveLen(1))
   116  			resultIndex := resultIndexes[0]
   117  			structmatcher.ExpectStructsToMatchExcluding(&resultIndex, &index, "Oid")
   118  		})
   119  		It("creates an index with statistics on expression columns", func() {
   120  			testutils.SkipIfBefore7(connectionPool)
   121  			indexes := []backup.IndexDefinition{{Oid: 0, Name: "testtable_index", OwningSchema: "public", OwningTable: "testtable", Def: sql.NullString{String: "CREATE INDEX testtable_index ON public.testtable USING btree (i, ((i + 1)), ((j * 2)))", Valid: true}, StatisticsColumns: "2,3", StatisticsValues: "5000,600"}}
   122  			backup.PrintCreateIndexStatements(backupfile, tocfile, indexes, indexMetadataMap)
   123  
   124  			//Create table whose columns we can index
   125  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.testtable(i int, j int)")
   126  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.testtable")
   127  
   128  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   129  
   130  			resultIndexes := backup.GetIndexes(connectionPool)
   131  			Expect(resultIndexes).To(HaveLen(1))
   132  			structmatcher.ExpectStructsToMatchExcluding(&resultIndexes[0], &indexes[0], "Oid")
   133  		})
   134  		It("creates a parition index and attaches it to the parent index", func() {
   135  			testutils.SkipIfBefore7(connectionPool)
   136  
   137  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.foopart_new (a integer, b integer) PARTITION BY RANGE (b) DISTRIBUTED BY (a)")
   138  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.foopart_new")
   139  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.foopart_new_p1 (a integer, b integer) DISTRIBUTED BY (a)")
   140  			testhelper.AssertQueryRuns(connectionPool, "ALTER TABLE ONLY public.foopart_new ATTACH PARTITION public.foopart_new_p1 FOR VALUES FROM (0) TO (1)")
   141  			testhelper.AssertQueryRuns(connectionPool, "CREATE INDEX fooidx ON ONLY public.foopart_new USING btree (b)")
   142  
   143  			partitionIndex := backup.IndexDefinition{Oid: 0, Name: "foopart_new_p1_b_idx", OwningSchema: "public", OwningTable: "foopart_new_p1", Def: sql.NullString{String: "CREATE INDEX foopart_new_p1_b_idx ON public.foopart_new_p1 USING btree (b)", Valid: true}, ParentIndexFQN: "public.fooidx"}
   144  
   145  			indexes := []backup.IndexDefinition{partitionIndex}
   146  			backup.PrintCreateIndexStatements(backupfile, tocfile, indexes, indexMetadataMap)
   147  
   148  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   149  			partitionIndex.Oid = testutils.OidFromObjectName(connectionPool, "", "foopart_new_p1_b_idx", backup.TYPE_INDEX)
   150  			partitionIndex.ParentIndex = testutils.OidFromObjectName(connectionPool, "", "fooidx", backup.TYPE_INDEX)
   151  
   152  			resultIndexes := backup.GetIndexes(connectionPool)
   153  			Expect(resultIndexes).To(HaveLen(2))
   154  			resultIndex := resultIndexes[1]
   155  
   156  			structmatcher.ExpectStructsToMatch(&resultIndex, &partitionIndex)
   157  		})
   158  	})
   159  	Describe("PrintCreateRuleStatements", func() {
   160  		var (
   161  			ruleMetadataMap backup.MetadataMap
   162  			ruleDef         string
   163  		)
   164  		BeforeEach(func() {
   165  			ruleMetadataMap = backup.MetadataMap{}
   166  			if false {
   167  				ruleDef = "CREATE RULE update_notify AS ON UPDATE TO public.testtable DO NOTIFY testtable;"
   168  			} else {
   169  				ruleDef = "CREATE RULE update_notify AS\n    ON UPDATE TO public.testtable DO\n NOTIFY testtable;"
   170  			}
   171  		})
   172  		It("creates a basic rule", func() {
   173  			rules := []backup.RuleDefinition{{Oid: 0, Name: "update_notify", OwningSchema: "public", OwningTable: "testtable", Def: sql.NullString{String: ruleDef, Valid: true}}}
   174  			backup.PrintCreateRuleStatements(backupfile, tocfile, rules, ruleMetadataMap)
   175  
   176  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.testtable(i int)")
   177  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.testtable")
   178  
   179  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   180  
   181  			resultRules := backup.GetRules(connectionPool)
   182  			Expect(resultRules).To(HaveLen(1))
   183  			structmatcher.ExpectStructsToMatchExcluding(&resultRules[0], &rules[0], "Oid")
   184  		})
   185  		It("creates a rule with a comment", func() {
   186  			rules := []backup.RuleDefinition{{Oid: 1, Name: "update_notify", OwningSchema: "public", OwningTable: "testtable", Def: sql.NullString{String: ruleDef, Valid: true}}}
   187  			ruleMetadataMap = testutils.DefaultMetadataMap("RULE", false, false, true, false)
   188  			ruleMetadata := ruleMetadataMap[rules[0].GetUniqueID()]
   189  			backup.PrintCreateRuleStatements(backupfile, tocfile, rules, ruleMetadataMap)
   190  
   191  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.testtable(i int)")
   192  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.testtable")
   193  
   194  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   195  
   196  			rules[0].Oid = testutils.OidFromObjectName(connectionPool, "", "update_notify", backup.TYPE_RULE)
   197  			resultRules := backup.GetRules(connectionPool)
   198  			resultMetadataMap := backup.GetCommentsForObjectType(connectionPool, backup.TYPE_RULE)
   199  			resultMetadata := resultMetadataMap[resultRules[0].GetUniqueID()]
   200  			Expect(resultRules).To(HaveLen(1))
   201  			structmatcher.ExpectStructsToMatchExcluding(&resultRules[0], &rules[0], "Oid")
   202  			structmatcher.ExpectStructsToMatch(&resultMetadata, &ruleMetadata)
   203  		})
   204  	})
   205  	Describe("PrintCreateTriggerStatements", func() {
   206  		var (
   207  			triggerMetadataMap backup.MetadataMap
   208  		)
   209  		BeforeEach(func() {
   210  			triggerMetadataMap = backup.MetadataMap{}
   211  		})
   212  		It("creates a basic trigger", func() {
   213  			triggerDef := `CREATE TRIGGER sync_testtable AFTER INSERT OR DELETE OR UPDATE ON public.testtable FOR EACH STATEMENT EXECUTE PROCEDURE "RI_FKey_check_ins"()`
   214  			if true {
   215  				triggerDef = `CREATE TRIGGER sync_testtable AFTER INSERT OR DELETE OR UPDATE ON public.testtable FOR EACH ROW EXECUTE FUNCTION "RI_FKey_check_ins"()`
   216  			}
   217  			triggers := []backup.TriggerDefinition{{Oid: 0, Name: "sync_testtable", OwningSchema: "public", OwningTable: "testtable", Def: sql.NullString{String: triggerDef, Valid: true}}}
   218  			backup.PrintCreateTriggerStatements(backupfile, tocfile, triggers, triggerMetadataMap)
   219  
   220  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.testtable(i int)")
   221  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.testtable")
   222  
   223  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   224  
   225  			resultTriggers := backup.GetTriggers(connectionPool)
   226  			Expect(resultTriggers).To(HaveLen(1))
   227  			structmatcher.ExpectStructsToMatchExcluding(&resultTriggers[0], &triggers[0], "Oid")
   228  		})
   229  		It("creates a trigger with a comment", func() {
   230  			triggerDef := `CREATE TRIGGER sync_testtable AFTER INSERT OR DELETE OR UPDATE ON public.testtable FOR EACH STATEMENT EXECUTE PROCEDURE "RI_FKey_check_ins"()`
   231  			if true {
   232  				triggerDef = `CREATE TRIGGER sync_testtable AFTER INSERT OR DELETE OR UPDATE ON public.testtable FOR EACH ROW EXECUTE FUNCTION "RI_FKey_check_ins"()`
   233  			}
   234  			triggers := []backup.TriggerDefinition{{Oid: 1, Name: "sync_testtable", OwningSchema: "public", OwningTable: "testtable", Def: sql.NullString{String: triggerDef, Valid: true}}}
   235  			triggerMetadataMap = testutils.DefaultMetadataMap("RULE", false, false, true, false)
   236  			triggerMetadata := triggerMetadataMap[triggers[0].GetUniqueID()]
   237  			backup.PrintCreateTriggerStatements(backupfile, tocfile, triggers, triggerMetadataMap)
   238  
   239  			testhelper.AssertQueryRuns(connectionPool, "CREATE TABLE public.testtable(i int)")
   240  			defer testhelper.AssertQueryRuns(connectionPool, "DROP TABLE public.testtable")
   241  
   242  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   243  
   244  			triggers[0].Oid = testutils.OidFromObjectName(connectionPool, "", "sync_testtable", backup.TYPE_TRIGGER)
   245  			resultTriggers := backup.GetTriggers(connectionPool)
   246  			resultMetadataMap := backup.GetCommentsForObjectType(connectionPool, backup.TYPE_TRIGGER)
   247  			resultMetadata := resultMetadataMap[resultTriggers[0].GetUniqueID()]
   248  			Expect(resultTriggers).To(HaveLen(1))
   249  			structmatcher.ExpectStructsToMatchExcluding(&resultTriggers[0], &triggers[0], "Oid")
   250  			structmatcher.ExpectStructsToMatch(&resultMetadata, &triggerMetadata)
   251  		})
   252  	})
   253  	Describe("PrintCreateEventTriggerStatements", func() {
   254  		BeforeEach(func() {
   255  			testutils.SkipIfBefore6(connectionPool)
   256  			testhelper.AssertQueryRuns(connectionPool, `CREATE FUNCTION abort_any_command()
   257  RETURNS event_trigger LANGUAGE plpgsql
   258  AS $$ BEGIN RAISE EXCEPTION 'exception'; END; $$;`)
   259  		})
   260  		AfterEach(func() {
   261  			testhelper.AssertQueryRuns(connectionPool, `DROP FUNCTION abort_any_command()`)
   262  		})
   263  		It("creates a basic event trigger", func() {
   264  			eventTriggers := []backup.EventTrigger{{Oid: 1, Name: "testeventtrigger1", Event: "ddl_command_start", FunctionName: "abort_any_command", Enabled: "O"}}
   265  			eventTriggerMetadataMap := backup.MetadataMap{}
   266  			backup.PrintCreateEventTriggerStatements(backupfile, tocfile, eventTriggers, eventTriggerMetadataMap)
   267  
   268  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   269  			defer testhelper.AssertQueryRuns(connectionPool, "DROP EVENT TRIGGER testeventtrigger1")
   270  
   271  			results := backup.GetEventTriggers(connectionPool)
   272  
   273  			Expect(results).To(HaveLen(1))
   274  			structmatcher.ExpectStructsToMatchExcluding(&eventTriggers[0], &results[0], "Oid")
   275  		})
   276  		It("creates an event trigger with multiple filter tags", func() {
   277  			eventTriggers := []backup.EventTrigger{{Oid: 1, Name: "testeventtrigger1", Event: "ddl_command_start", FunctionName: "abort_any_command", Enabled: "O", EventTags: `'DROP FUNCTION', 'DROP TABLE'`}}
   278  			eventTriggerMetadataMap := backup.MetadataMap{}
   279  			backup.PrintCreateEventTriggerStatements(backupfile, tocfile, eventTriggers, eventTriggerMetadataMap)
   280  
   281  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   282  			defer testhelper.AssertQueryRuns(connectionPool, "DROP EVENT TRIGGER testeventtrigger1")
   283  
   284  			results := backup.GetEventTriggers(connectionPool)
   285  
   286  			Expect(results).To(HaveLen(1))
   287  			structmatcher.ExpectStructsToMatchExcluding(&eventTriggers[0], &results[0], "Oid")
   288  		})
   289  		It("creates an event trigger with a single filter tag and enable option", func() {
   290  			eventTriggers := []backup.EventTrigger{{Oid: 1, Name: "testeventtrigger1", Event: "ddl_command_start", FunctionName: "abort_any_command", Enabled: "R", EventTags: `'DROP FUNCTION'`}}
   291  			eventTriggerMetadataMap := backup.MetadataMap{}
   292  			backup.PrintCreateEventTriggerStatements(backupfile, tocfile, eventTriggers, eventTriggerMetadataMap)
   293  
   294  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   295  			defer testhelper.AssertQueryRuns(connectionPool, "DROP EVENT TRIGGER testeventtrigger1")
   296  
   297  			results := backup.GetEventTriggers(connectionPool)
   298  
   299  			Expect(results).To(HaveLen(1))
   300  			structmatcher.ExpectStructsToMatchExcluding(&eventTriggers[0], &results[0], "Oid")
   301  		})
   302  		It("creates an event trigger with comment, security label, and owner", func() {
   303  			eventTriggers := []backup.EventTrigger{{Oid: 1, Name: "test_event_trigger", Event: "ddl_command_start", FunctionName: "abort_any_command", Enabled: "O"}}
   304  			eventTriggerMetadataMap := testutils.DefaultMetadataMap("EVENT TRIGGER", false, true, true, includeSecurityLabels)
   305  			eventTriggerMetadata := eventTriggerMetadataMap[eventTriggers[0].GetUniqueID()]
   306  
   307  			backup.PrintCreateEventTriggerStatements(backupfile, tocfile, []backup.EventTrigger{eventTriggers[0]}, eventTriggerMetadataMap)
   308  
   309  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   310  			defer testhelper.AssertQueryRuns(connectionPool, "DROP EVENT TRIGGER test_event_trigger")
   311  
   312  			resultEventTriggers := backup.GetEventTriggers(connectionPool)
   313  			resultMetadataMap := backup.GetMetadataForObjectType(connectionPool, backup.TYPE_EVENTTRIGGER)
   314  
   315  			Expect(resultEventTriggers).To(HaveLen(1))
   316  			uniqueID := testutils.UniqueIDFromObjectName(connectionPool, "", "test_event_trigger", backup.TYPE_EVENTTRIGGER)
   317  			resultMetadata := resultMetadataMap[uniqueID]
   318  			structmatcher.ExpectStructsToMatchExcluding(&eventTriggers[0], &resultEventTriggers[0], "Oid")
   319  			structmatcher.ExpectStructsToMatch(&eventTriggerMetadata, &resultMetadata)
   320  
   321  		})
   322  	})
   323  	Describe("PrintCreateExtendedStatistics", func() {
   324  		BeforeEach(func() {
   325  			testutils.SkipIfBefore7(connectionPool)
   326  			testhelper.AssertQueryRuns(connectionPool, `CREATE SCHEMA schema1;`)
   327  			testhelper.AssertQueryRuns(connectionPool, `CREATE TABLE schema1.table_for_ext_stats (m int, n int);`)
   328  		})
   329  		AfterEach(func() {
   330  			testhelper.AssertQueryRuns(connectionPool, `DROP TABLE schema1.table_for_ext_stats;`)
   331  			testhelper.AssertQueryRuns(connectionPool, `DROP SCHEMA schema1;`)
   332  		})
   333  		It("creates an extended statistics", func() {
   334  			extStats := []backup.StatisticExt{{Oid: 1, Name: "myextstatistics", Namespace: "public", Owner: "testrole", TableSchema: "schema1", TableName: "table_for_ext_stats", Definition: "CREATE STATISTICS public.myextstatistics (dependencies) ON m, n FROM schema1.table_for_ext_stats"}}
   335  
   336  			statisticsMetadataMap := backup.MetadataMap{}
   337  			backup.PrintCreateExtendedStatistics(backupfile, tocfile, extStats, statisticsMetadataMap)
   338  
   339  			testhelper.AssertQueryRuns(connectionPool, buffer.String())
   340  			defer testhelper.AssertQueryRuns(connectionPool, "DROP STATISTICS public.myextstatistics")
   341  
   342  			results := backup.GetExtendedStatistics(connectionPool)
   343  
   344  			Expect(results).To(HaveLen(1))
   345  			structmatcher.ExpectStructsToMatchExcluding(&extStats[0], &results[0], "Oid")
   346  		})
   347  	})
   348  	Describe("PrintExchangedPartitionIndexes", func() {
   349  		BeforeEach(func() {
   350  			if true {
   351  				Skip("Test only applicable to GPDB6")
   352  			}
   353  			testhelper.AssertQueryRuns(connectionPool, `CREATE SCHEMA schemaone;`)
   354  		})
   355  		AfterEach(func() {
   356  			testhelper.AssertQueryRuns(connectionPool, `DROP SCHEMA schemaone CASCADE;`)
   357  		})
   358  
   359  		It("creates exchanged partition table indexes correctly", func() {
   360  			testhelper.AssertQueryRuns(connectionPool, `
   361                      CREATE TABLE schemaone.pt_heap_tab(a INT, b TEXT, c INT , d INT, e NUMERIC, success BOOL) WITH (appendonly=false)
   362                      DISTRIBUTED BY (a)
   363                      PARTITION BY list(b)
   364                      (
   365                               PARTITION abc VALUES ('abc','abc1','abc2') WITH (appendonly=false),
   366                               PARTITION def VALUES ('def','def1','def3') WITH (appendonly=true, compresslevel=1), 
   367                               PARTITION ghi VALUES ('ghi','ghi1','ghi2') WITH (appendonly=true),
   368                               default partition dft
   369                      );
   370  
   371  					CREATE INDEX heap_idx1 ON schemaone.pt_heap_tab(a) WHERE c > 10;
   372  					ALTER TABLE schemaone.pt_heap_tab DROP default partition;
   373  
   374  					CREATE TABLE schemaone.heap_can(LIKE schemaone.pt_heap_tab INCLUDING INDEXES);
   375  
   376  					ALTER TABLE schemaone.pt_heap_tab ADD PARTITION pqr VALUES ('pqr','pqr1','pqr2') WITH (appendonly=true, orientation=column, compresslevel=5);
   377  					ALTER TABLE schemaone.pt_heap_tab EXCHANGE PARTITION FOR ('pqr') WITH table schemaone.heap_can;`)
   378  
   379  			indexes := backup.GetIndexes(connectionPool)
   380  			backup.RenameExchangedPartitionIndexes(connectionPool, &indexes)
   381  			indexesMetadataMap := backup.MetadataMap{}
   382  			backup.PrintCreateIndexStatements(backupfile, tocfile, indexes, indexesMetadataMap)
   383  
   384  			// Automatically-generated index names end in "_idx" in 6+ and "_key" in earlier versions.
   385  			if true {
   386  				Expect(strings.Contains(buffer.String(), `CREATE INDEX heap_can_a_idx`)).To(BeTrue())
   387  				Expect(strings.Contains(buffer.String(), `CREATE INDEX pt_heap_tab_1_prt_pqr_a_idx`)).To(BeFalse())
   388  			} else {
   389  				Expect(strings.Contains(buffer.String(), `CREATE INDEX heap_can_a_key`)).To(BeTrue())
   390  				Expect(strings.Contains(buffer.String(), `CREATE INDEX pt_heap_tab_1_prt_pqr_a_key`)).To(BeFalse())
   391  			}
   392  		})
   393  	})
   394  })