r/SQL • • 2d ago

SQL Server Negative reseed risks

One of the Sqlserver tables had an int identity column and maxed out the value. Team planned to reseed the identity from the lowest-ve value so that it can run on the same datatype for another 5 or 6 years. I am thinking that this would be a costly mistake if they plan to migrate this data into a new platform. The original solution was to change this to a bigint. Since this field has 300+ fks all those need to be dropped and recreated. What could possibly go wrong by choosing a -ve value reseed? I see the daily seed count is topping approximately 1 to 1.5million ids.

8 Upvotes

21 comments sorted by

2

u/SQLBek 1d ago

Michael J Swart has a couple of good blog posts on how he converted to bigint, if that's the path you choose. Dig those up

1

u/clakshminarasu 1d ago

Thanks man!!

7

u/mr_bottle_of_turkeys 2d ago

Ah, the classic "we'll just use the negative space" gambit. Seen it go from "temporary workaround" to permanent nightmare in about three months.

The FK cascade alone is a nightmare, but the real fun starts when some reporting tool or API integration silently treats that column as unsigned and suddenly your negative IDs map to nothing, or worse, the wrong records. Hope they've got good docs and a strong drink.

1

u/clakshminarasu 2d ago

Yup. I agree. Let's assume that this specific field is just a surrogate + it's a hierarchical, the same table has another column, parent id which will do a self join and will never be used in reports or in the downstream loads. Just views, tons of views which has all the jobs under the hood. This field is clustered indexed, so, I think it's going to start writing to new pages, and performance will become a problem day by day, eventually.

4

u/BarfingOnMyFace 2d ago

Oh negative values. I remember someone who would use negatives to represent a different state of a thing, maybe deleted or something of the sort, can no longer recall.. god fucking awful.

2

u/RockFourStar 1d ago edited 1d ago

I agree with the sentiment and that where possible people should design a fix rather thana workaround. But my main taleaway there is simply this: "3 months? That is one busy table"

The main time I saw this we were warning the business for well over a year and I thought that was busy.

In that instance I found out they breached the initial threshold sometime after I left for a more senior role elsewhere. Apparently management did the old "No one warned us about this" routine.

The guy that told me was a platform guy rather than a DB professional and was one of the people along with me who had raised this and helped produce the good old excel charts predicting the exact time this would fail, had also moved on to an even more senior role elsewhere. We both had a good laugh when he told me about the protests of innocence.

1

u/lolcrunchy 2d ago

My AI spidey sense is tingling on this comment from this 4mo account

1

u/IAmADev_NoReallyIAm 1d ago

Nothing is more permanent than a temporary fix.

2

u/mike-manley 2d ago

Did you consider refactoring with UUIDs (GUIDs in SS)?

1

u/clakshminarasu 2d ago edited 2d ago

That's a very good point. How about existing data? Also how does it perform on a 500 million record table and With 300+fks?

1

u/Available_Safe1818 1d ago

You should be able to test it out for yourself on a similar testing table.

1

u/reditandfirgetit 1d ago

Change it to a bigint. Reseeding creates way more risk.

3

u/Hour-Measurement-835 2d ago

Not sure if 1.5M a day is your peak or it's still climbing, but at 1.5M the negative half runs out in about 3.9 years. The 5 or 6 only works if you stay near 1M.

3

u/saucerattack 1d ago

Been there. Done that. Regretted it. Be kind to future you and convert to BIGINT now. It's painful but take the hit and put a reminder on your calendar for 2031 to thank yourself that you aren't converting a table twice as big.

2

u/thatOMoment 2d ago

Changing to bigint will also require rebuilding indexes. Also requires adjusting clients and servers to handle larger numeric types. 

Thats going to be a project

2

u/IAmADev_NoReallyIAm 1d ago

Database wise, converting it to an unsigned bigint probably carries the least amount of risk and gives the longest amount of life. From a client site... that's a big shift.

Using UUIDs/GUIDs would also be a good alternative, again, safe on the database side, but a huge undertaking from the client side.

Anything else is risky from a data integrity pov. There will always be an invisible undocumented soft FKey that gets missed and doesn't get updated.

2

u/PX3better 11h ago

It works just fine, but immediately plan to migrate to bigint or maybe UUID.

1

u/freshrobin440 1d ago

If that's the clustered index, negative reseeds flip inserts from the tail of the index to the head. At 1.5M a day that fragmentation builds fast.

1

u/SonOfZork 1d ago

One of the best ones I've seen is the application failing to handle negative values on the key column and it breaking the app entirely.

1

u/blackleather90 1d ago

Like anything, it is a trade off.
Negative numbers could lead to the unsigned issue already mentioned.
BIGINT requires all referenced tables to be updated. It also runs the risk of any vars being int on any use of those fields across all objects that use those fields.

Good luck!

0

u/jshine13371 2d ago

Any queries that depend on that column being ordered will potentially be logically wrong moving forward. E.g. if a query expects that column to represent the order that the rows were created and perhaps does something like uses it to deterministically break ties in a window function. The logic will now be different.

Outside of that, I don't think it's as big of a deal as everyone else mentioned. The other risks are much lower in reality.