Why is dropping a primary key expensive? [duplicate]What happens when you delete a Clustered index and Non Clustered Index once createdImplications of using a Unique NonClustered Index with Covering Columns instead of a Primary KeyWhy are timestamps not always increasing with concurrent inserts?Should I mark a composite index as unique if it contains the primary key?How to split a wide table in Production?Speeding up insert in SQL ServerWhat can be the downside of always having a single integer column as primary key?SQL Server: Clustered index, sorting and paginationChanging the datatype of the primary key columns of partitioned tableswhy is update from a join containing zero records taking a minute and 20 seconds?What are the reasons to create a key-less, index-less database?

How to forge a multi-part weapon?

How can "научись" mean "take it and keep trying"?

Does Disney no longer produce hand-drawn cartoon films?

Find the limit of a multiplying term function when n tends to infinity.

Share calendar details request from manager's manager

How can electric fields be used to detect cracks in metals?

SQL counting distinct over partition

How does an ordinary object become radioactive?

Winning Strategy for the Magician and his Apprentice

Do simulator games use a realistic trajectory to get into orbit?

Pre-1972 sci-fi short story or novel: alien(?) tunnel where people try new moves and get destroyed if they're not the correct ones

Should I avoid hard-packed crusher dust trails with my hybrid?

Overlapping String-Blocks

How can I tell the difference between unmarked sugar and stevia?

What is the `some` keyword in SwiftUI?

What is the actual quality of machine translations?

Soft question: Examples where lack of mathematical rigour cause security breaches?

How come the nude protesters were not arrested?

1980s live-action movie where individually-coloured nations on clouds fight

Motivation - or how can I get myself to do the work I know I need to?

What makes an item an artifact?

Impedance ratio vs. SWR

Mobile App Appraisal

How to construct an hbox with negative height?



Why is dropping a primary key expensive? [duplicate]


What happens when you delete a Clustered index and Non Clustered Index once createdImplications of using a Unique NonClustered Index with Covering Columns instead of a Primary KeyWhy are timestamps not always increasing with concurrent inserts?Should I mark a composite index as unique if it contains the primary key?How to split a wide table in Production?Speeding up insert in SQL ServerWhat can be the downside of always having a single integer column as primary key?SQL Server: Clustered index, sorting and paginationChanging the datatype of the primary key columns of partitioned tableswhy is update from a join containing zero records taking a minute and 20 seconds?What are the reasons to create a key-less, index-less database?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3
















This question already has an answer here:



  • What happens when you delete a Clustered index and Non Clustered Index once created

    1 answer



I have a table with a clustered PK. No foreign keys reference it. When I drop it I expect it to be more or less instantaneous, but it is instead very slow.



My assumption was that we'd just be removing some metadata and not having a constraint or clustering for future updates and inserts.



What is actually happening internally to make this expensive?










share|improve this question















marked as duplicate by mustaccio, Paul White sql-server
Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 30 at 9:08


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • I admit the answer and the underlying issues are the same in this as in the referenced question. However, I somewhat object to the duplicate flag. The words primary key do not appear in the other question. The presence and importance of the nonclustered index is only revealed the discussion and answer to this one. I searched before posting and did not wind up with at the other answer. I think there is value in this as a standalone question even if the answer is the same.

    – Karl Kieninger
    May 30 at 15:44

















3
















This question already has an answer here:



  • What happens when you delete a Clustered index and Non Clustered Index once created

    1 answer



I have a table with a clustered PK. No foreign keys reference it. When I drop it I expect it to be more or less instantaneous, but it is instead very slow.



My assumption was that we'd just be removing some metadata and not having a constraint or clustering for future updates and inserts.



What is actually happening internally to make this expensive?










share|improve this question















marked as duplicate by mustaccio, Paul White sql-server
Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 30 at 9:08


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • I admit the answer and the underlying issues are the same in this as in the referenced question. However, I somewhat object to the duplicate flag. The words primary key do not appear in the other question. The presence and importance of the nonclustered index is only revealed the discussion and answer to this one. I searched before posting and did not wind up with at the other answer. I think there is value in this as a standalone question even if the answer is the same.

    – Karl Kieninger
    May 30 at 15:44













3












3








3









This question already has an answer here:



  • What happens when you delete a Clustered index and Non Clustered Index once created

    1 answer



I have a table with a clustered PK. No foreign keys reference it. When I drop it I expect it to be more or less instantaneous, but it is instead very slow.



My assumption was that we'd just be removing some metadata and not having a constraint or clustering for future updates and inserts.



What is actually happening internally to make this expensive?










share|improve this question

















This question already has an answer here:



  • What happens when you delete a Clustered index and Non Clustered Index once created

    1 answer



I have a table with a clustered PK. No foreign keys reference it. When I drop it I expect it to be more or less instantaneous, but it is instead very slow.



My assumption was that we'd just be removing some metadata and not having a constraint or clustering for future updates and inserts.



What is actually happening internally to make this expensive?





This question already has an answer here:



  • What happens when you delete a Clustered index and Non Clustered Index once created

    1 answer







sql-server






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited May 30 at 0:36







Karl Kieninger

















asked May 30 at 0:18









Karl KieningerKarl Kieninger

1937




1937




marked as duplicate by mustaccio, Paul White sql-server
Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 30 at 9:08


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by mustaccio, Paul White sql-server
Users with the  sql-server badge can single-handedly close sql-server questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
May 30 at 9:08


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • I admit the answer and the underlying issues are the same in this as in the referenced question. However, I somewhat object to the duplicate flag. The words primary key do not appear in the other question. The presence and importance of the nonclustered index is only revealed the discussion and answer to this one. I searched before posting and did not wind up with at the other answer. I think there is value in this as a standalone question even if the answer is the same.

    – Karl Kieninger
    May 30 at 15:44

















  • I admit the answer and the underlying issues are the same in this as in the referenced question. However, I somewhat object to the duplicate flag. The words primary key do not appear in the other question. The presence and importance of the nonclustered index is only revealed the discussion and answer to this one. I searched before posting and did not wind up with at the other answer. I think there is value in this as a standalone question even if the answer is the same.

    – Karl Kieninger
    May 30 at 15:44
















I admit the answer and the underlying issues are the same in this as in the referenced question. However, I somewhat object to the duplicate flag. The words primary key do not appear in the other question. The presence and importance of the nonclustered index is only revealed the discussion and answer to this one. I searched before posting and did not wind up with at the other answer. I think there is value in this as a standalone question even if the answer is the same.

– Karl Kieninger
May 30 at 15:44





I admit the answer and the underlying issues are the same in this as in the referenced question. However, I somewhat object to the duplicate flag. The words primary key do not appear in the other question. The presence and importance of the nonclustered index is only revealed the discussion and answer to this one. I searched before posting and did not wind up with at the other answer. I think there is value in this as a standalone question even if the answer is the same.

– Karl Kieninger
May 30 at 15:44










1 Answer
1






active

oldest

votes


















11














One of the reasons dropping the PK constraint, and the underlying clustered index, is expensive is that the underlying data is transformed into a HEAP. This affects all of the non-clustered indexes which have to update the pointers back to the row data from the old clustered index key to the new HEAP row. From Docs:




The pointer from an index row in a nonclustered index to a data row is
called a row locator. The structure of the row locator depends on
whether the data pages are stored in a heap or a clustered table. For
a heap, a row locator is a pointer to the row. For a clustered table,
the row locator is the clustered index key.




So once you drop the PK and clustered index, the non-clustered indexes have their row locators updated from the clustered index key to the heap pointer. Depending on the size and number of indexes, there is potentially a substantial cost involved in this update.



This is also explained in this article:




Dropping a clustered index can take time because in addition to
dropping the clustered index, all nonclustered indexes on the table
must be rebuilt to replace the clustered index keys with row pointers
to the heap.







share|improve this answer





























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    11














    One of the reasons dropping the PK constraint, and the underlying clustered index, is expensive is that the underlying data is transformed into a HEAP. This affects all of the non-clustered indexes which have to update the pointers back to the row data from the old clustered index key to the new HEAP row. From Docs:




    The pointer from an index row in a nonclustered index to a data row is
    called a row locator. The structure of the row locator depends on
    whether the data pages are stored in a heap or a clustered table. For
    a heap, a row locator is a pointer to the row. For a clustered table,
    the row locator is the clustered index key.




    So once you drop the PK and clustered index, the non-clustered indexes have their row locators updated from the clustered index key to the heap pointer. Depending on the size and number of indexes, there is potentially a substantial cost involved in this update.



    This is also explained in this article:




    Dropping a clustered index can take time because in addition to
    dropping the clustered index, all nonclustered indexes on the table
    must be rebuilt to replace the clustered index keys with row pointers
    to the heap.







    share|improve this answer



























      11














      One of the reasons dropping the PK constraint, and the underlying clustered index, is expensive is that the underlying data is transformed into a HEAP. This affects all of the non-clustered indexes which have to update the pointers back to the row data from the old clustered index key to the new HEAP row. From Docs:




      The pointer from an index row in a nonclustered index to a data row is
      called a row locator. The structure of the row locator depends on
      whether the data pages are stored in a heap or a clustered table. For
      a heap, a row locator is a pointer to the row. For a clustered table,
      the row locator is the clustered index key.




      So once you drop the PK and clustered index, the non-clustered indexes have their row locators updated from the clustered index key to the heap pointer. Depending on the size and number of indexes, there is potentially a substantial cost involved in this update.



      This is also explained in this article:




      Dropping a clustered index can take time because in addition to
      dropping the clustered index, all nonclustered indexes on the table
      must be rebuilt to replace the clustered index keys with row pointers
      to the heap.







      share|improve this answer

























        11












        11








        11







        One of the reasons dropping the PK constraint, and the underlying clustered index, is expensive is that the underlying data is transformed into a HEAP. This affects all of the non-clustered indexes which have to update the pointers back to the row data from the old clustered index key to the new HEAP row. From Docs:




        The pointer from an index row in a nonclustered index to a data row is
        called a row locator. The structure of the row locator depends on
        whether the data pages are stored in a heap or a clustered table. For
        a heap, a row locator is a pointer to the row. For a clustered table,
        the row locator is the clustered index key.




        So once you drop the PK and clustered index, the non-clustered indexes have their row locators updated from the clustered index key to the heap pointer. Depending on the size and number of indexes, there is potentially a substantial cost involved in this update.



        This is also explained in this article:




        Dropping a clustered index can take time because in addition to
        dropping the clustered index, all nonclustered indexes on the table
        must be rebuilt to replace the clustered index keys with row pointers
        to the heap.







        share|improve this answer













        One of the reasons dropping the PK constraint, and the underlying clustered index, is expensive is that the underlying data is transformed into a HEAP. This affects all of the non-clustered indexes which have to update the pointers back to the row data from the old clustered index key to the new HEAP row. From Docs:




        The pointer from an index row in a nonclustered index to a data row is
        called a row locator. The structure of the row locator depends on
        whether the data pages are stored in a heap or a clustered table. For
        a heap, a row locator is a pointer to the row. For a clustered table,
        the row locator is the clustered index key.




        So once you drop the PK and clustered index, the non-clustered indexes have their row locators updated from the clustered index key to the heap pointer. Depending on the size and number of indexes, there is potentially a substantial cost involved in this update.



        This is also explained in this article:




        Dropping a clustered index can take time because in addition to
        dropping the clustered index, all nonclustered indexes on the table
        must be rebuilt to replace the clustered index keys with row pointers
        to the heap.








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 30 at 0:58









        HandyDHandyD

        2,8161320




        2,8161320













            Popular posts from this blog

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form