Skip to content

Hash Partitioning on primary key (long) doesn't work #4023

Closed

Description

@MaksimSimkin

We have a class With Primary Key Id (long) and we want to have hash partitions on this table:

    public class Stuck
    {
        public long Id { get; set; }
...
    }
            var hashValues = Enumerable.Range(0, NumberOfPartitions)
                .Select(i=>$"mt_doc_stuck_part_{i:00}")
                .ToArray();

            options.Schema.For<Stuck>()
                .PartitionOn(x=>x.Id, x=>x.ByHash(hashValues));

On SQL generation for this table we are running in issue, that Marten is trying to duplicate Id Column for partitions, having already an id pk column.

Activity

  1. mysticmind commented on Nov 18, 2025

    @mysticmind
    Member

    @MaksimSimkin why would you partition a table using its primary id? You should be partitioning by some other property other than the primary id. Possibly, if you are using Stuck.Id as a foreign key or something in a different table and if you partition that table using say StuckId, it makes sense.

    Edit: If you want to use some sort of a partition number then that has to a property on Stuck like PartitionNumber and then you have to partition on it and not on Id

  2. MaksimSimkin commented on Nov 18, 2025

    @MaksimSimkin
    Author

    @mysticmind If i am doing partition on primary id i have always more or less equal amount of data in each partition, and i don't need to take care if the property i use is distributed the sam equally.
    But actually the answer is: because i have it already. We are using marten in Version 3, our huge table has already this partitions and now we want to upgrade marten to latest version without database changes.

  3. mysticmind commented on Nov 18, 2025

    @mysticmind
    Member

    Got it, you have a pre-existing partition which you created yourself and now you are trying to use the Marten provided partitioning thinking it would seamlessly work. I think, you may want to check what Marten does for partitioning as a logic and get the state of your existing db in the exact similar way to get going.

  4. mysticmind commented on Nov 18, 2025

    @mysticmind
    Member

    If i am doing partition on primary id i have always more or less equal amount of data in each partition, and i don't need to take care if the property i use is distributed the sam equally.

    Makes sense, gotcha!

  5. mysticmind commented on Nov 18, 2025

    @mysticmind
    Member

    This is not a bug per se. So converting this to a discussion.

  6. locked and limited conversation to collaborators on Nov 18, 2025
  7. converted this issue into a discussion #4024 on Nov 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions