From 93529969c7ff959f7477b411750207cc07b9efdb Mon Sep 17 00:00:00 2001 From: HustonMmmavr Date: Tue, 5 Sep 2023 13:50:13 +0300 Subject: [PATCH] use separate function to prevent incorrect behaviour --- backup/queries_relations.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/backup/queries_relations.go b/backup/queries_relations.go index 25525bb7c..d56b47c45 100644 --- a/backup/queries_relations.go +++ b/backup/queries_relations.go @@ -27,7 +27,7 @@ func relationAndSchemaFilterClause() string { quotedExcludeRelations, err := options.QuoteTableNames(connectionPool, MustGetFlagStringArray(options.EXCLUDE_RELATION)) gplog.FatalOnError(err) - excludeOids := getOidsFromRelationList(connectionPool, quotedExcludeRelations) + excludeOids := getExcludedRelationOidsList(connectionPool, quotedExcludeRelations) if len(excludeOids) > 0 { filterRelationClause += fmt.Sprintf("\nAND c.oid NOT IN (%s)", strings.Join(excludeOids, ", ")) } @@ -42,26 +42,35 @@ func relationAndSchemaFilterClause() string { return filterRelationClause } -func getOidsFromRelationList(connectionPool *dbconn.DBConn, quotedIncludeRelations []string) []string { +func getExcludedRelationOidsList(connectionPool *dbconn.DBConn, quotedIncludeRelations []string) []string { relList := utils.SliceToQuotedString(quotedIncludeRelations) - // is this solution correct for cases with include query := fmt.Sprintf(` WITH root_oids AS ( - SELECT c.oid AS a + SELECT c.oid AS _oid FROM pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid WHERE quote_ident(n.nspname) || '.' || quote_ident(c.relname) IN (%s) ) - SELECT a FROM root_oids + SELECT _oid FROM root_oids UNION - SELECT r.parchildrelid as string + SELECT r.parchildrelid as _oid FROM pg_partition p join pg_partition_rule r on p.oid = r.paroid join root_oids oids on p.parrelid = oids.a WHERE r.parchildrelid != 0 `, relList) return dbconn.MustSelectStringSlice(connectionPool, query) } +func getOidsFromRelationList(connectionPool *dbconn.DBConn, quotedIncludeRelations []string) []string { + relList := utils.SliceToQuotedString(quotedIncludeRelations) + query := fmt.Sprintf(` + SELECT c.oid AS string + FROM pg_class c + JOIN pg_namespace n ON c.relnamespace = n.oid + WHERE quote_ident(n.nspname) || '.' || quote_ident(c.relname) IN (%s)`, relList) + return dbconn.MustSelectStringSlice(connectionPool, query) +} + func GetIncludedUserTableRelations(connectionPool *dbconn.DBConn, includedRelationsQuoted []string) []Relation { if len(MustGetFlagStringArray(options.INCLUDE_RELATION)) > 0 { return getUserTableRelationsWithIncludeFiltering(connectionPool, includedRelationsQuoted)