Implementation of support for sub-partitioning and a category and time based sub-partioning strategy #273
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements sub-partitioning for PostgreSQL in django-postgres-extra, and a strategy to have LIST partitions on the first and (date) RANGE partitions on the second level.
Our use-case for this was that we would like to partition a table first on an an integer column, and then use a CurrentTimePartitioning strategy to further sub-partition using a date column, and use
pgpartitionfor partition management.We can declare a sub-partitioned model like this:
The
PostgresCategoryCurrentTimePartitioningStrategycreates and manages first and second level partitions, and can be used like this:Resulting in first level partitions
mypartitionedmodel_1,mypartitionedmodel_2,mypartitionedmodel_100and second level partitionsmypartitionedmodel_1_2026,mypartitionedmodel_1_2027,mypartitionedmodel_1_2028,mypartitionedmodel_2_2026...The implementation aimed to only make minimal changes to the basecode and implements most functions by overwriting classes as a contributing module.
If the PR is acceptable in principle, the new model classes
PostgresListPartitionandPostgresTimeSubPartition, as well as theadd_list_partition,add_range_partitionand possiblyadd_hash_partitionin the schema editor, could be further consolidated to allow additional sub-partitioning scenarios other than LIST and RANGE.