February 15, 2023 at 5:16 pm
I have a memory optimized table with identity column. The primary key is a combination of a project ID and the identity column. The problem I have is that the identity column is close to reaching it's limit. The table gets deleted periodically, but the identity keeps increasing. I could switch to bigint but I don't want to do that.
My true solution is to use row_number() over (order by XXX) for each project as the number increases and remove the identity column. However, window functions (over clause) are not supported in natively compiled stored procedures.
Is there an alternative, or code I could use in natively compiled stored procedures that would achieve my goal?
February 15, 2023 at 5:28 pm
It is possible and straightforward to reset the IDENTITY property of a column after deleting rows in its table. Would that solve your problem?
The absence of evidence is not evidence of absence.
Martin Rees
You can lead a horse to water, but a pencil must be lead.
Stan Laurel
February 15, 2023 at 6:11 pm
Reseeding of memory optimized tables are not supported; that is, DBCC CHECKIDENT ('mytable', RESEED, 0) is not supported for memory optimized table whether done inside or outside of a natively compiled stored procedure.
I thought of creating a memory optimized table type with an identity column. That will always reseed to 1 at the start of the procedure. At the end of the procedure I can store the data in the permanent memory optimized table. However, I'm concerned about the performance having to create the memory optimized table from the table type every time the procedure is called.
February 15, 2023 at 6:12 pm
Truncate statement is not supported for memory optimized tables.
February 15, 2023 at 6:16 pm
I suppose the question, then, is why do you keep deleting all the data and then inserting it (again?)? What is the need to delete all the rows and then provide new ones?
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
February 15, 2023 at 9:02 pm
Unfortunately, sequences are also not allowed. That was actually my very first option.
February 15, 2023 at 9:37 pm
You are at the edge of a cliff. I strongly recommend you turn around and go another way.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 16, 2023 at 7:35 pm
I found an alternative to my specific problem. I used the identity to also sort the data and had another column that I could use to sort the data. I removed the identity column, have other uniqueness in the table where I could create the primary key and the sorted on the column I had.
However, I did not find a solution to the problem I originally posted. Thanks, everyone for the replies.
February 16, 2023 at 7:47 pm
I found an alternative to my specific problem. I used the identity to also sort the data and had another column that I could use to sort the data. I removed the identity column, have other uniqueness in the table where I could create the primary key and the sorted on the column I had.
However, I did not find a solution to the problem I originally posted. Thanks, everyone for the replies.
Thanks for the feedback on what you've done. I do have a question, though... why was "Natively Compiled" stored procedures so important in this case? And, not asking to be challenging or a smart-guy about it. I've not used such a thing before and we have an issue at one of the companies I do some work for suggested that particular methodology. I've read the propaganda about it but there's absolutely nothing better than getting the opinion of someone that has actually used the feature.
--Jeff Moden
Change is inevitable... Change for the better is not.
February 17, 2023 at 3:26 pm
Jeff, when done right, natively compiled stored procedure achieve incredible performance gains. They are compiled software (DLLs), much like C++ code. The problem is that there are many limitations and you may have to loop one row at a time in some instances. But even then, it is still faster than interpreted stored procedures.
February 17, 2023 at 3:39 pm
Jeff, when done right, natively compiled stored procedure achieve incredible performance gains. They are compiled software (DLLs), much like C++ code. The problem is that there are many limitations and you may have to loop one row at a time in some instances. But even then, it is still faster than interpreted stored procedures.
Thank you for taking the time to provide some feedback on my question. And, yes, I totally understood that that's the claim. But, did you actually realize such a performance gain in this particular case?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 13 posts - 1 through 12 (of 12 total)
You must be logged in to reply to this topic. Login to reply