Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 856251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:12:24+00:00 2026-05-15T08:12:24+00:00

If I start using a HiLo generator to assign ID’s for a table, and

  • 0

If I start using a HiLo generator to assign ID’s for a table, and then decide to increase or decrease the capacity (i.e. the maximum ‘lo’ value), will this cause collisions with the already-assigned ID’s?

I’m just wondering if I need to put a big red flag around the number saying ‘Don’t ever change this!’

Note – not NHibernate specific, I’m just curious about the HiLo algorithm in general.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T08:12:24+00:00Added an answer on May 15, 2026 at 8:12 am

    HiLo algorithms in general basically map two integers to one integer ID. It guarantees that the pair of numbers will be unique per database. Typically, the next step is to guarantee that a unique pair of numbers maps to a unique integer ID.

    A nice explanation of how HiLo conceptually works is given in this previous SO answer

    Changing the max_lo will preserve the property that your pair of numbers will be unique. However, will it make sure that the mapped ID is unique and collision-free?

    Let’s look at Hibernate’s implementation of HiLo. The algorithm they appear to use (as from what I’ve gathered) is: (and I might be off on a technicality)

    h = high sequence (starting at 0)
    l_size = size of low block
    l = low sequence (starting at 1)
    
    ID = h*l_size + l
    

    So, if your low block is, say, 100, your reserved ID blocks would go 1-100, 101-200, 201-300, 301-400…

    Your High sequence is now 3. Now what would happen if you all of a sudden changed your l_size to 10? Your next block, your High is incremented, and you’d get 4*10+1 = 41

    Oops. This new value definitely falls within the “reserved block” of 1-100. Someone with a high sequence of 0 would think, “Well, I have the range 1-100 reserved just for me, so I’ll just put down one at 41, because I know it’s safe.”

    There is definitely a very, very high chance of collision when lowering your l_max.

    What about the opposite case, raising it?

    Back to our example, let’s raise our l_size to 500, turning the next key into 4*500+1 = 2001, reserving the range 2001-2501.

    It looks like collision will be avoided, in this particular implementation of HiLo, when raising your l_max.

    Of course, you should do some own tests on your own to make sure that this is the actual implementation, or close to it. One way would be to set l_max to 100 and find the first few keys, then set it to 500 and find the next. If there is a huge jump like mentioned here, you might be safe.

    However, I am not by any means suggesting that it is best practice to raise your l_max on an existing database.

    Use your own discretion; the HiLo algorithm isn’t exactly one made with varying l_max in mind, and your results may in the end be unpredictable depending on your exact implementation. Maybe someone who has had experience with raising their l_max and finding troubles can prove this count correct.

    So in conclusion, even though, in theory, Hibernate’s HiLo implementation will most likely avoid collisions when l_max is raised, it probably still isn’t good practice. You should code as if l_max were not going to change over time.

    But if you’re feeling lucky…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 432k
  • Answers 432k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use FireBug to find out why. Perhaps the second time… May 15, 2026 at 2:35 pm
  • Editorial Team
    Editorial Team added an answer After looking at a bunch of config files I discovered… May 15, 2026 at 2:35 pm
  • Editorial Team
    Editorial Team added an answer Tell latex to align it at the top of the… May 15, 2026 at 2:35 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.