Allow marking partition columns #5353
Replies: 2 comments 8 replies
-
Good idea, I like it.
I assume that Hibernate Shards died for a good reason :) So I agree: much better to support what the databases offer natively.
I don’t hate it, and it sorta seems like a nice thing to have, but on the other hand it’s also the sort of thing that you only really need in the sort of schema that we don’t recommend the use of SchemaExport for. So I dunno if it’s really worth doing this, as opposed to just giving people a way to append some arbitrary SQL to the end of generated |
Beta Was this translation helpful? Give feedback.
-
Could you please explain the purpose of |
Beta Was this translation helpful? Give feedback.
-
The idea is, to introduce an annotation e.g.
@PartitionColumn
, which can be used to mark persistent attributes/columns that are partition columns. The effect of the annotation is, thatupdate
anddelete
statements executed through entity flushing will mention theinitialState
of partition columns in thewhere
clause, which will allow the query planner of the database to do partition pruning and target the correct partition table instead of possibly looking into every possible partition table.We could of course go one step further and explore adding support for application based partitioning, but I don't think this is reasonable, given that all major databases support partitioning natively already.
It might be interesting though to generate DDL for the partitioning type and maybe also allow configuring initial partitions or so. A portable way to declare common partition types could be done through the following annotations:@PartitionByRange({ @RangePartition(tableName = "...", from = "...", to = "...") })
@PartitionByList({ @ListPartition(tableName = "...", keys = {...}) })
@PartitionByHash({ @HashPartition(tableName = "...", modulus = 3, remainder = 0) })
The DDL part is just an idea, but I'm happy to create a dedicated design discussion for a more concrete proposal.See #5360 for further discussions about DDL support.
Any thoughts on the
@PartitionColumn
annotation? My proposal for the definition would be:This allows specifying partition columns in embeddables and also for collection tables. For join tables (*-to-many), I think we simply can't reasonably support partition columns, as we have no place where we could store the value. I'd say that people who want to use partition columns in "join tables", will have to map these tables as entities.
See https://hibernate.atlassian.net/browse/HHH-15899
Beta Was this translation helpful? Give feedback.
All reactions