ADBDEV-5169: Add the ability to backup partitions whose parent is in the extension#74
ADBDEV-5169: Add the ability to backup partitions whose parent is in the extension#74andr-sokolov merged 27 commits intomasterfrom
Conversation
In 7X, if you add a partition to the partitioned table created by the extension, the backup attempt would fail. The reason was that when receiving information about table inheritance, tables related to extensions were filtered out, and therefore the added partitions did not have a link to the parent partition. This patch fixes the getUserTableRelations function to ignore partitions whose root is in the extension, as is done in 6X. The filtering of extension tables from GetTableInheritance has also been removed in order to correctly handle situations when the parent table is added to extensions.
927f0b7 to
0e9cc84
Compare
| JOIN pg_namespace n ON p.relnamespace = n.oid | ||
| WHERE %s%s | ||
| ORDER BY i.inhrelid, i.inhseqno`, | ||
| ExtensionFilterClause("p"), tableFilterStr) |
There was a problem hiding this comment.
Why did you removed ExtensionFilterClause for 5X and 6X?
There was a problem hiding this comment.
in 6X, we can also lose inheritance during backup if the parent is in the extension.
backup/queries_table_defs.go
Outdated
| // If we are filtering on tables, we only want to record dependencies on other tables in the list | ||
| if len(tableOidList) > 0 { | ||
| tableFilterStr = fmt.Sprintf("\nAND i.inhrelid IN (%s)", strings.Join(tableOidList, ",")) | ||
| tableFilterStr = fmt.Sprintf("WHERE i.inhrelid IN (%s)", strings.Join(tableOidList, ",")) |
There was a problem hiding this comment.
Are you sure it is good idea to put where in condition variable?
There was a problem hiding this comment.
Since we have no other conditions, WHERE is needed only in the case of this filter.
This reverts commit fd90de7.
This reverts commit 7df8224.
This reverts commit fedc752.
This reverts commit 4561cc9.
This reverts commit 236a12b.
This reverts commit 0e9cc84.
This patch adds the ability to backup partitions of tables in the extension that were added after the extension was created. Several issues have also been fixed: 1. We no longer get panic when trying to backup a 7X cluster in which there are partitioned tables in the extension, some partitions of which are outside the extension. This was due to the fact that when we received the parent tables, we filtered out the tables in the extension. 2. In 6X, if the table was inherited from a table in the extension, we we no longer lost inheritance during backup. 3. When backing up a 6X cluster, we no longer ignore partitions not from the extension of tables in the extension, but only if the '--leaf-partition-data' flag is present, since the COPY command to the intermediate table in 6X does not return anything.
1. updated comments 2. Combined the PrintExchangeExternalPartitionStatements and PrintAlterExtensionTablesStatements functions 3. The old behavior for include-tables for 6X has been returned since the sibling backup is the expected behavior. 4. The tests use special functions to verify the correctness of the recovery.
|
I have some new questions/comments.
User script: When I try to backup this using the latest version on 6x, the user partition is not backed up. It seems that previous version of patch backed up this partition. Is it an expected behavior?
|
KnightMurloc
left a comment
There was a problem hiding this comment.
- Actually, the difference is not that big between 6X and 7X. In 6X, we to do SPLIT the default partition in case it is in the table. In 7X, we need to do SPLIT only if the default partition contains data related to the new partition. Therefore, in 6X it is important for us to create a default partition the last ones, and in 7X the order is not important to us.
- Has the
--leaf-partition-dataflag been set? if not, then skipping such partitions is the expected behavior. I checked with me if the--leaf-partition-dataflag is set, then the user partition will be backed up.
I also want to check how query plans were changed, but will do this later. |
This reverts commit f053187.
This reverts commit 32c52e7.
This reverts commit 495ed7b
…xtension" This reverts commit 1c90839.
This patch adds the ability to backup partitions of partitioned tables whose root is in the extension for gpdb 7. We can backup partitions that are outside the extension if no data is added to the default partition in the extension creation script, otherwise we will get an error when restoring from the backup. Because when adding a new partition, the constants on the default partition change, and if the data in the partition does not meet the new constraints, we will get an error. If such a situation occurs during restore, you should exclude problematic partitions using --exclude-table, where you need to specify the name of the root partition. Also fixed panic in 7X in case parent tables are in the extension.
The updated explanation looks too informal and contains a lot of pronounces. Please format PR message according to points in our wiki. |
KnightMurloc
left a comment
There was a problem hiding this comment.
the constants on the default partition change -> (here I just don't understand what you mean)
when we create a partitioned table with a default partition, a constraint is added to it:
Partition constraint: (NOT ((a IS NOT NULL) AND (((a >= 0) AND (a < 1)) OR ((a >= 1) AND (a < 2)) OR ((a >= 2) AND (a < 3)))))
simplified looks like this:
NOT ((a IS NOT NULL) AND (a = 0 OR a = 1 OR a = 2))
if we add a partition for a = 1. the constraint will change to:
NOT ((a IS NOT NULL) AND (a = 0 OR a = 2))
And if the default partition contains rows with a = 1, we will get an error.
|
Overall ok, but the PR description should be updated to highlight current situation, what abilities current code missed and what was changed to achieve them (including difference in 6x and 7x behavior). Already explained case is just a special case, but it can be linked with existed test. |
… that hinder restore if the default partition in the extension contains data' test
Add the ability to backup partitions whose parent is in the extension
In 7X, if there was a partition in the database whose parent was in the
extension, then the backup attempt would have ended in panic. This was due to
the fact that when receiving the names of the parent tables, the tables in the
extension were filtered out, which led to a reference to nil when creating DDL
for ATTACH PARTITION.
This patch fixes the panic by removing the filtering of tables in the extension
for 7X.
This patch also adds the ability to backup such partitions in 7X. For 6X and
earlier, the old behavior was left in order not to violate the established
behavior.
There is a situation when, after a backup of the database with such partitions,
an error may appear when restoring. This can happen if data is added to the
default partition in the extension creation script. Then, during the restore,
when creating a new partition, the default partition constraints will change,
and if the data in the default partition does not meet the new constraints, an
error will appear. If such a situation occurs, problematic partitions should be
excluded using --exclude-table, where a root partition is specified. There is a
test for this case: "allows the user to exclude partitions that hinder restore
if the default partition in the extension contains data".