Skip to content

Commit

Permalink
use separate function to prevent incorrect behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
HustonMmmavr committed Sep 5, 2023
1 parent 005393b commit 9352996
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions backup/queries_relations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ", "))
}
Expand All @@ -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)
Expand Down

0 comments on commit 9352996

Please sign in to comment.