Insert into table with identity insert taking almost a secondMySQL query 'going away' on executing INSERT ON...

Having the player face themselves after the mid-game

What materials can be used to make a humanoid skin warm?

Is it possible that a question has only two answers?

Can I use a violin G string for D?

Is a piano played in the same way as a harmonium?

When a wind turbine does not produce enough electricity how does the power company compensate for the loss?

Would an aboleth's Phantasmal Force lair action be affected by Counterspell, Dispel Magic, and/or Slow?

Are all players supposed to be able to see each others' character sheets?

Is it safe to abruptly remove Arduino power?

Why couldn't the separatists legally leave the Republic?

What are some noteworthy "mic-drop" moments in math?

Minimizing with differential evolution

Is it a Cyclops number? "Nobody" knows!

How do spaceships determine each other's mass in space?

Which classes are needed to have access to every spell in the PHB?

How can I get players to focus on the story aspect of D&D?

How does Ehrenfest's theorem apply to the quantum harmonic oscillator?

Recommendation letter by significant other if you worked with them professionally?

How to check whether module is loaded with custom configurations?

For which categories of spectra is there an explicit description of the fibrant objects via lifting properties?

Is it possible to avoid unpacking when merging Association?

Haman going to the second feast dirty

Source permutation

After `ssh` without `-X` to a machine, is it possible to change `$DISPLAY` to make it work like `ssh -X`?



Insert into table with identity insert taking almost a second


MySQL query 'going away' on executing INSERT ON DUPLICATE UPDATE statement with a 12524 character blobTempInsertStateItemShort procedure on ASPState is taking more than 1 second to executeHigh PAGELATCH_* and WRITELOG waits. Are they related?T-SQL insert value based on identity columnUpdating a table from another databaseHow to make a query on multiple columns without writting all possible permutations?Insert openquery results into an existing tableDB Index MaintenanceInsert statement on one table blocking delete on another unrelated table on sql serverInsert into Table ignoring duplicate values













1















We have an oltp application and I am trying to troubleshoot why insert into one of our table is taking close to a second. Not all inserts are taking this much time but there are some which does take close to a second and since this insert is part of business transaction which can only take around 200ms, a one second insert is a problem.



This table has a primary key which is identity and is nonclustered. Clustered index is another column.



The insert stored procedure is very simple. Something like



Create proc usptable_insert
( a bunch of parameters)
as
insert into table (col1, col2 ........)
values (parameters1, parameter2...... etc)
DECLARE @Id INT = (SELECT SCOPE_IDENTITY());
SET IDENTITY_INSERT [table2] ON
insert into table2 (col1, col2 ........)
values (@Id, parameter2...... etc
SET IDENTITY_INSERT [table2] OFF


We are in the process of migrating from table1 to table2 hence inserting into two tables and using identity insert to make sure table2 has same keys.



First two rows are the the insert statements
enter image description here



Initially I thought it was because of latch contention because of hotspot issue on the last page. But I tried to reproduce this in pre-prod by running this stored procedure through sqlstress with 100 threads and couldn't.



If I am not wrong this behaviors cannot be blocking as its an insert and unless something is blocking the whole table which is not the case.



What can be other reasons for this behavious?










share|improve this question














bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 2





    Since your clustered index is not the Identity column AND since you indicated that not every insert takes a long time, you may be experiencing delays due to page splits on the clustered index. There are numerous ways to diagnose page splits - Try searching the Internet.

    – Scott Hodgin
    Sep 25 '18 at 12:22











  • That makes sense. I havent pursuit that angle, but since it did not come up in pre-prod, i am less hopeful. Thanks for the comment.

    – ilovesql
    Sep 25 '18 at 20:56











  • Tested in pre-prod by doing inserts that would cause pagesplit, but that did not bring up the execution count to a second.

    – ilovesql
    Sep 26 '18 at 1:57
















1















We have an oltp application and I am trying to troubleshoot why insert into one of our table is taking close to a second. Not all inserts are taking this much time but there are some which does take close to a second and since this insert is part of business transaction which can only take around 200ms, a one second insert is a problem.



This table has a primary key which is identity and is nonclustered. Clustered index is another column.



The insert stored procedure is very simple. Something like



Create proc usptable_insert
( a bunch of parameters)
as
insert into table (col1, col2 ........)
values (parameters1, parameter2...... etc)
DECLARE @Id INT = (SELECT SCOPE_IDENTITY());
SET IDENTITY_INSERT [table2] ON
insert into table2 (col1, col2 ........)
values (@Id, parameter2...... etc
SET IDENTITY_INSERT [table2] OFF


We are in the process of migrating from table1 to table2 hence inserting into two tables and using identity insert to make sure table2 has same keys.



First two rows are the the insert statements
enter image description here



Initially I thought it was because of latch contention because of hotspot issue on the last page. But I tried to reproduce this in pre-prod by running this stored procedure through sqlstress with 100 threads and couldn't.



If I am not wrong this behaviors cannot be blocking as its an insert and unless something is blocking the whole table which is not the case.



What can be other reasons for this behavious?










share|improve this question














bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.











  • 2





    Since your clustered index is not the Identity column AND since you indicated that not every insert takes a long time, you may be experiencing delays due to page splits on the clustered index. There are numerous ways to diagnose page splits - Try searching the Internet.

    – Scott Hodgin
    Sep 25 '18 at 12:22











  • That makes sense. I havent pursuit that angle, but since it did not come up in pre-prod, i am less hopeful. Thanks for the comment.

    – ilovesql
    Sep 25 '18 at 20:56











  • Tested in pre-prod by doing inserts that would cause pagesplit, but that did not bring up the execution count to a second.

    – ilovesql
    Sep 26 '18 at 1:57














1












1








1








We have an oltp application and I am trying to troubleshoot why insert into one of our table is taking close to a second. Not all inserts are taking this much time but there are some which does take close to a second and since this insert is part of business transaction which can only take around 200ms, a one second insert is a problem.



This table has a primary key which is identity and is nonclustered. Clustered index is another column.



The insert stored procedure is very simple. Something like



Create proc usptable_insert
( a bunch of parameters)
as
insert into table (col1, col2 ........)
values (parameters1, parameter2...... etc)
DECLARE @Id INT = (SELECT SCOPE_IDENTITY());
SET IDENTITY_INSERT [table2] ON
insert into table2 (col1, col2 ........)
values (@Id, parameter2...... etc
SET IDENTITY_INSERT [table2] OFF


We are in the process of migrating from table1 to table2 hence inserting into two tables and using identity insert to make sure table2 has same keys.



First two rows are the the insert statements
enter image description here



Initially I thought it was because of latch contention because of hotspot issue on the last page. But I tried to reproduce this in pre-prod by running this stored procedure through sqlstress with 100 threads and couldn't.



If I am not wrong this behaviors cannot be blocking as its an insert and unless something is blocking the whole table which is not the case.



What can be other reasons for this behavious?










share|improve this question














We have an oltp application and I am trying to troubleshoot why insert into one of our table is taking close to a second. Not all inserts are taking this much time but there are some which does take close to a second and since this insert is part of business transaction which can only take around 200ms, a one second insert is a problem.



This table has a primary key which is identity and is nonclustered. Clustered index is another column.



The insert stored procedure is very simple. Something like



Create proc usptable_insert
( a bunch of parameters)
as
insert into table (col1, col2 ........)
values (parameters1, parameter2...... etc)
DECLARE @Id INT = (SELECT SCOPE_IDENTITY());
SET IDENTITY_INSERT [table2] ON
insert into table2 (col1, col2 ........)
values (@Id, parameter2...... etc
SET IDENTITY_INSERT [table2] OFF


We are in the process of migrating from table1 to table2 hence inserting into two tables and using identity insert to make sure table2 has same keys.



First two rows are the the insert statements
enter image description here



Initially I thought it was because of latch contention because of hotspot issue on the last page. But I tried to reproduce this in pre-prod by running this stored procedure through sqlstress with 100 threads and couldn't.



If I am not wrong this behaviors cannot be blocking as its an insert and unless something is blocking the whole table which is not the case.



What can be other reasons for this behavious?







sql-server performance sql-server-2014






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 25 '18 at 11:55









ilovesqlilovesql

61




61





bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.










  • 2





    Since your clustered index is not the Identity column AND since you indicated that not every insert takes a long time, you may be experiencing delays due to page splits on the clustered index. There are numerous ways to diagnose page splits - Try searching the Internet.

    – Scott Hodgin
    Sep 25 '18 at 12:22











  • That makes sense. I havent pursuit that angle, but since it did not come up in pre-prod, i am less hopeful. Thanks for the comment.

    – ilovesql
    Sep 25 '18 at 20:56











  • Tested in pre-prod by doing inserts that would cause pagesplit, but that did not bring up the execution count to a second.

    – ilovesql
    Sep 26 '18 at 1:57














  • 2





    Since your clustered index is not the Identity column AND since you indicated that not every insert takes a long time, you may be experiencing delays due to page splits on the clustered index. There are numerous ways to diagnose page splits - Try searching the Internet.

    – Scott Hodgin
    Sep 25 '18 at 12:22











  • That makes sense. I havent pursuit that angle, but since it did not come up in pre-prod, i am less hopeful. Thanks for the comment.

    – ilovesql
    Sep 25 '18 at 20:56











  • Tested in pre-prod by doing inserts that would cause pagesplit, but that did not bring up the execution count to a second.

    – ilovesql
    Sep 26 '18 at 1:57








2




2





Since your clustered index is not the Identity column AND since you indicated that not every insert takes a long time, you may be experiencing delays due to page splits on the clustered index. There are numerous ways to diagnose page splits - Try searching the Internet.

– Scott Hodgin
Sep 25 '18 at 12:22





Since your clustered index is not the Identity column AND since you indicated that not every insert takes a long time, you may be experiencing delays due to page splits on the clustered index. There are numerous ways to diagnose page splits - Try searching the Internet.

– Scott Hodgin
Sep 25 '18 at 12:22













That makes sense. I havent pursuit that angle, but since it did not come up in pre-prod, i am less hopeful. Thanks for the comment.

– ilovesql
Sep 25 '18 at 20:56





That makes sense. I havent pursuit that angle, but since it did not come up in pre-prod, i am less hopeful. Thanks for the comment.

– ilovesql
Sep 25 '18 at 20:56













Tested in pre-prod by doing inserts that would cause pagesplit, but that did not bring up the execution count to a second.

– ilovesql
Sep 26 '18 at 1:57





Tested in pre-prod by doing inserts that would cause pagesplit, but that did not bring up the execution count to a second.

– ilovesql
Sep 26 '18 at 1:57










1 Answer
1






active

oldest

votes


















0















If I am not wrong this behaviors cannot be blocking as its an insert
and unless something is blocking the whole table which is not the
case.




What is your isolation level? Read Committed?



If there are selects running on table or table2 then blocking could occur and slow down some of the inserts, as you are seeing.



You could test with read commited snapshot isolation level and use row versioning if blocking is the case.
You need to know the implications for your tempdb (version store will grow, long running open transactions can be problematic for your tempdb)



To enable RSSI:



ALTER DATABASE MyDatabase  
SET ALLOW_SNAPSHOT_ISOLATION ON

ALTER DATABASE MyDatabase
SET READ_COMMITTED_SNAPSHOT ON


Otherwise you could issue a profiler session to get more information on the issue. It is hard to answer (apart from obvious blocking) without more details.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "182"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f218501%2finsert-into-table-with-identity-insert-taking-almost-a-second%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0















    If I am not wrong this behaviors cannot be blocking as its an insert
    and unless something is blocking the whole table which is not the
    case.




    What is your isolation level? Read Committed?



    If there are selects running on table or table2 then blocking could occur and slow down some of the inserts, as you are seeing.



    You could test with read commited snapshot isolation level and use row versioning if blocking is the case.
    You need to know the implications for your tempdb (version store will grow, long running open transactions can be problematic for your tempdb)



    To enable RSSI:



    ALTER DATABASE MyDatabase  
    SET ALLOW_SNAPSHOT_ISOLATION ON

    ALTER DATABASE MyDatabase
    SET READ_COMMITTED_SNAPSHOT ON


    Otherwise you could issue a profiler session to get more information on the issue. It is hard to answer (apart from obvious blocking) without more details.






    share|improve this answer




























      0















      If I am not wrong this behaviors cannot be blocking as its an insert
      and unless something is blocking the whole table which is not the
      case.




      What is your isolation level? Read Committed?



      If there are selects running on table or table2 then blocking could occur and slow down some of the inserts, as you are seeing.



      You could test with read commited snapshot isolation level and use row versioning if blocking is the case.
      You need to know the implications for your tempdb (version store will grow, long running open transactions can be problematic for your tempdb)



      To enable RSSI:



      ALTER DATABASE MyDatabase  
      SET ALLOW_SNAPSHOT_ISOLATION ON

      ALTER DATABASE MyDatabase
      SET READ_COMMITTED_SNAPSHOT ON


      Otherwise you could issue a profiler session to get more information on the issue. It is hard to answer (apart from obvious blocking) without more details.






      share|improve this answer


























        0












        0








        0








        If I am not wrong this behaviors cannot be blocking as its an insert
        and unless something is blocking the whole table which is not the
        case.




        What is your isolation level? Read Committed?



        If there are selects running on table or table2 then blocking could occur and slow down some of the inserts, as you are seeing.



        You could test with read commited snapshot isolation level and use row versioning if blocking is the case.
        You need to know the implications for your tempdb (version store will grow, long running open transactions can be problematic for your tempdb)



        To enable RSSI:



        ALTER DATABASE MyDatabase  
        SET ALLOW_SNAPSHOT_ISOLATION ON

        ALTER DATABASE MyDatabase
        SET READ_COMMITTED_SNAPSHOT ON


        Otherwise you could issue a profiler session to get more information on the issue. It is hard to answer (apart from obvious blocking) without more details.






        share|improve this answer














        If I am not wrong this behaviors cannot be blocking as its an insert
        and unless something is blocking the whole table which is not the
        case.




        What is your isolation level? Read Committed?



        If there are selects running on table or table2 then blocking could occur and slow down some of the inserts, as you are seeing.



        You could test with read commited snapshot isolation level and use row versioning if blocking is the case.
        You need to know the implications for your tempdb (version store will grow, long running open transactions can be problematic for your tempdb)



        To enable RSSI:



        ALTER DATABASE MyDatabase  
        SET ALLOW_SNAPSHOT_ISOLATION ON

        ALTER DATABASE MyDatabase
        SET READ_COMMITTED_SNAPSHOT ON


        Otherwise you could issue a profiler session to get more information on the issue. It is hard to answer (apart from obvious blocking) without more details.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 25 '18 at 12:31









        Randi VertongenRandi Vertongen

        3,293822




        3,293822






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Database Administrators Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f218501%2finsert-into-table-with-identity-insert-taking-almost-a-second%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Anexo:Material bélico de la Fuerza Aérea de Chile Índice Aeronaves Defensa...

            Always On Availability groups resolving state after failover - Remote harden of transaction...

            update json value to null Announcing the arrival of Valued Associate #679: Cesar Manara ...