Adding List and Range based partitioning #196
Open
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.
Basics:
This PR adds the ability for PGDog to support List and Range based partitioning in addition to the existing Hash method. Conceptually, the code simply looks at the configuration to see if the partition key's value is defined within a given shard. If the key value is not found the query will be routed to
Shard::All
Summary of changes
pgdoc/src/config/shards.rs
with the majority of the config structs and implementation logic.pgdoc/src/config/mod.rs
for integrating into the ShardedTable structpgdoc/src/frontend/sharding/values.rs
to integrate into Routing and Operatorspgdoc/src/frontend/sharding/operator.rs
to integrate into Routing and Operatorspgdoc/src/frontend/sharding/context.rs
to integrate into Routing and Operatorspgdoc/src/frontend/sharding/context_builder.rs
to integrate into Routing and OperatorsSupported Datatypes
Currently only
bigint
is supported however ideally these can support floats, strings and datetimes in the future.Config changes
3 fields have been added to the ShardedTables configuration. Because this defaults to hash partitioning, the configuration should be compatible with previously valid configs.
sharding_method
: This controls what sharding method is used. defaults tohash
, other options arelist
andrange
shard_list_map
: This holds the config for a map of shards (0,1 etc) to a list of values. If the partitioned column's value is in a list the query will be sent to the specified shard. It is possible for lists to overlap, in which case the first one found will be returned.shard_range_map
: This provides the ability to define ranges instead of using discrete values (as with the list).Example Configs:
Range based sharding:
List based sharding: