How to determine the cost of index creation?How to determine if an Index is required or necessaryAre existing entries immediately included into a newly created index?Error while creating index in SQL AzureIs Index causing timeouts?Will an index that is a partial key of the begining of another index perform any better than the longer index?Speed up creation of Postgres partial indexOracle index usageCreating index for specific values onlySQLite DB from file vs “service”Eliminating a intra query deadlock, can I avoid restricting parallelism?

Is this toilet slogan correct usage of the English language?

Why is it that I can sometimes guess the next note?

Did the UK lift the requirement for registering SIM cards?

Does the reader need to like the PoV character?

Non-trope happy ending?

What is the English pronunciation of "pain au chocolat"?

Find the next value of this number series

Has any country ever had 2 former presidents in jail simultaneously?

Has the laser at Magurele, Romania reached a tenth of the Sun's power?

A variation to the phrase "hanging over my shoulders"

PTIJ: Why is Haman obsessed with Bose?

Giving feedback to someone without sounding prejudiced

Shouldn’t conservatives embrace universal basic income?

What kind of floor tile is this?

Why do ¬, ∀ and ∃ have the same precedence?

In a multiple cat home, how many litter boxes should you have?

awk assign to multiple variables at once

Permission on Database

How would you translate "more" for use as an interface button?

Why does Carol not get rid of the Kree symbol on her suit when she changes its colours?

"before" and "want" for the same systemd service?

How can ping know if my host is down

What (the heck) is a Super Worm Equinox Moon?

How do I fix the group tension caused by my character stealing and possibly killing without provocation?



How to determine the cost of index creation?


How to determine if an Index is required or necessaryAre existing entries immediately included into a newly created index?Error while creating index in SQL AzureIs Index causing timeouts?Will an index that is a partial key of the begining of another index perform any better than the longer index?Speed up creation of Postgres partial indexOracle index usageCreating index for specific values onlySQLite DB from file vs “service”Eliminating a intra query deadlock, can I avoid restricting parallelism?













2















I have a table that I want to create an index on to improve the performance of a couple of SELECT queries that use the table.



How can I test whether the index has had any significant detrimental impact on DUI operations on the table?



The table is a log table, so it is written to frequently. Is it a case of running a particular INSERT or UPDATE query against that table before and after creating the desired index?










share|improve this question



















  • 3





    This is far too broad a question the way you've asked it. You should post the table definition and potential index definition, because those will likely be some deciding factors. For instance, if your logging table has a MAX column, and you wanna have that as included column, it's probably a dumb idea.

    – Erik Darling
    Mar 14 at 12:41















2















I have a table that I want to create an index on to improve the performance of a couple of SELECT queries that use the table.



How can I test whether the index has had any significant detrimental impact on DUI operations on the table?



The table is a log table, so it is written to frequently. Is it a case of running a particular INSERT or UPDATE query against that table before and after creating the desired index?










share|improve this question



















  • 3





    This is far too broad a question the way you've asked it. You should post the table definition and potential index definition, because those will likely be some deciding factors. For instance, if your logging table has a MAX column, and you wanna have that as included column, it's probably a dumb idea.

    – Erik Darling
    Mar 14 at 12:41













2












2








2








I have a table that I want to create an index on to improve the performance of a couple of SELECT queries that use the table.



How can I test whether the index has had any significant detrimental impact on DUI operations on the table?



The table is a log table, so it is written to frequently. Is it a case of running a particular INSERT or UPDATE query against that table before and after creating the desired index?










share|improve this question
















I have a table that I want to create an index on to improve the performance of a couple of SELECT queries that use the table.



How can I test whether the index has had any significant detrimental impact on DUI operations on the table?



The table is a log table, so it is written to frequently. Is it a case of running a particular INSERT or UPDATE query against that table before and after creating the desired index?







sql-server performance sql-server-2014 index






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 14 at 16:56









Josh Darnell

6,97022140




6,97022140










asked Mar 14 at 10:37









SEarle1986SEarle1986

517317




517317







  • 3





    This is far too broad a question the way you've asked it. You should post the table definition and potential index definition, because those will likely be some deciding factors. For instance, if your logging table has a MAX column, and you wanna have that as included column, it's probably a dumb idea.

    – Erik Darling
    Mar 14 at 12:41












  • 3





    This is far too broad a question the way you've asked it. You should post the table definition and potential index definition, because those will likely be some deciding factors. For instance, if your logging table has a MAX column, and you wanna have that as included column, it's probably a dumb idea.

    – Erik Darling
    Mar 14 at 12:41







3




3





This is far too broad a question the way you've asked it. You should post the table definition and potential index definition, because those will likely be some deciding factors. For instance, if your logging table has a MAX column, and you wanna have that as included column, it's probably a dumb idea.

– Erik Darling
Mar 14 at 12:41





This is far too broad a question the way you've asked it. You should post the table definition and potential index definition, because those will likely be some deciding factors. For instance, if your logging table has a MAX column, and you wanna have that as included column, it's probably a dumb idea.

– Erik Darling
Mar 14 at 12:41










1 Answer
1






active

oldest

votes


















10














If you have a non-production environment, you could simulate your insert / update workload by running SQL Query Stress. Do that before adding the index to get a baseline, and then after to see how much slower it is, and whether that change is acceptable.



In addition to additional overhead for your DUI operations, another consideration is blocking. You might have different blocking patterns than you're used to, since some SELECT queries will be using the new index, and inserts / updates will have to take locks on that index and the clustered index.



I only point this out to make the point that DUI "overhead" is not the only consideration. Adding indexes can often help with blocking, since SELECT queries on the narrower NC index won't be blocked by updates to other columns in the clustered index.




Without knowing anything about your table, here's a quick walkthrough of what the SQL Query Stress approach might look like. I'll set up a "LogTable" in a new database:



USE [master];
GO

CREATE DATABASE [232113];
GO

ALTER DATABASE [232113] SET RECOVERY SIMPLE WITH NO_WAIT;
GO

USE [232113];
GO

CREATE TABLE dbo.LogTable
(
Id INT PRIMARY KEY IDENTITY(1,1),
Col1 DATETIME NOT NULL,
Col2 CHAR(4) NOT NULL
);


Then I use these two queries to simulate the INSERT / UPDATE workload:



-- insert a row
INSERT INTO dbo.LogTable
(Col1, Col2)
VALUES
(GETDATE(), 'val2');

-- update a random row
UPDATE dbo.LogTable
SET Col2 = 'val3'
WHERE Id = (SELECT TOP (1) Id
FROM dbo.LogTable
ORDER BY NEWID());


Then I run SQL Query Stress over 6 threads, 250 iterations per thread, with a 100 ms delay between each execution. This completes in about 25 seconds with just the clustered index in place.



screenshot of SQL Query Stress results



Now I'll create a nonclustered index on Col2, which is affected by both the inserts and the updates:



CREATE NONCLUSTERED INDEX IX_Col2 ON dbo.LogTable (Col2);


Running the test again, it took basically the same amount of time (25 seconds). Notice that the logical reads went up, so there is some cost here (it just didn't affect the overall duration).



screenshot of SQL Query Stress results



Of course, this is a very simple case, with no other activity on the "server" (my laptop), so the difference is minimal. But hopefully it demonstrates the concept.






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%2f232113%2fhow-to-determine-the-cost-of-index-creation%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









    10














    If you have a non-production environment, you could simulate your insert / update workload by running SQL Query Stress. Do that before adding the index to get a baseline, and then after to see how much slower it is, and whether that change is acceptable.



    In addition to additional overhead for your DUI operations, another consideration is blocking. You might have different blocking patterns than you're used to, since some SELECT queries will be using the new index, and inserts / updates will have to take locks on that index and the clustered index.



    I only point this out to make the point that DUI "overhead" is not the only consideration. Adding indexes can often help with blocking, since SELECT queries on the narrower NC index won't be blocked by updates to other columns in the clustered index.




    Without knowing anything about your table, here's a quick walkthrough of what the SQL Query Stress approach might look like. I'll set up a "LogTable" in a new database:



    USE [master];
    GO

    CREATE DATABASE [232113];
    GO

    ALTER DATABASE [232113] SET RECOVERY SIMPLE WITH NO_WAIT;
    GO

    USE [232113];
    GO

    CREATE TABLE dbo.LogTable
    (
    Id INT PRIMARY KEY IDENTITY(1,1),
    Col1 DATETIME NOT NULL,
    Col2 CHAR(4) NOT NULL
    );


    Then I use these two queries to simulate the INSERT / UPDATE workload:



    -- insert a row
    INSERT INTO dbo.LogTable
    (Col1, Col2)
    VALUES
    (GETDATE(), 'val2');

    -- update a random row
    UPDATE dbo.LogTable
    SET Col2 = 'val3'
    WHERE Id = (SELECT TOP (1) Id
    FROM dbo.LogTable
    ORDER BY NEWID());


    Then I run SQL Query Stress over 6 threads, 250 iterations per thread, with a 100 ms delay between each execution. This completes in about 25 seconds with just the clustered index in place.



    screenshot of SQL Query Stress results



    Now I'll create a nonclustered index on Col2, which is affected by both the inserts and the updates:



    CREATE NONCLUSTERED INDEX IX_Col2 ON dbo.LogTable (Col2);


    Running the test again, it took basically the same amount of time (25 seconds). Notice that the logical reads went up, so there is some cost here (it just didn't affect the overall duration).



    screenshot of SQL Query Stress results



    Of course, this is a very simple case, with no other activity on the "server" (my laptop), so the difference is minimal. But hopefully it demonstrates the concept.






    share|improve this answer



























      10














      If you have a non-production environment, you could simulate your insert / update workload by running SQL Query Stress. Do that before adding the index to get a baseline, and then after to see how much slower it is, and whether that change is acceptable.



      In addition to additional overhead for your DUI operations, another consideration is blocking. You might have different blocking patterns than you're used to, since some SELECT queries will be using the new index, and inserts / updates will have to take locks on that index and the clustered index.



      I only point this out to make the point that DUI "overhead" is not the only consideration. Adding indexes can often help with blocking, since SELECT queries on the narrower NC index won't be blocked by updates to other columns in the clustered index.




      Without knowing anything about your table, here's a quick walkthrough of what the SQL Query Stress approach might look like. I'll set up a "LogTable" in a new database:



      USE [master];
      GO

      CREATE DATABASE [232113];
      GO

      ALTER DATABASE [232113] SET RECOVERY SIMPLE WITH NO_WAIT;
      GO

      USE [232113];
      GO

      CREATE TABLE dbo.LogTable
      (
      Id INT PRIMARY KEY IDENTITY(1,1),
      Col1 DATETIME NOT NULL,
      Col2 CHAR(4) NOT NULL
      );


      Then I use these two queries to simulate the INSERT / UPDATE workload:



      -- insert a row
      INSERT INTO dbo.LogTable
      (Col1, Col2)
      VALUES
      (GETDATE(), 'val2');

      -- update a random row
      UPDATE dbo.LogTable
      SET Col2 = 'val3'
      WHERE Id = (SELECT TOP (1) Id
      FROM dbo.LogTable
      ORDER BY NEWID());


      Then I run SQL Query Stress over 6 threads, 250 iterations per thread, with a 100 ms delay between each execution. This completes in about 25 seconds with just the clustered index in place.



      screenshot of SQL Query Stress results



      Now I'll create a nonclustered index on Col2, which is affected by both the inserts and the updates:



      CREATE NONCLUSTERED INDEX IX_Col2 ON dbo.LogTable (Col2);


      Running the test again, it took basically the same amount of time (25 seconds). Notice that the logical reads went up, so there is some cost here (it just didn't affect the overall duration).



      screenshot of SQL Query Stress results



      Of course, this is a very simple case, with no other activity on the "server" (my laptop), so the difference is minimal. But hopefully it demonstrates the concept.






      share|improve this answer

























        10












        10








        10







        If you have a non-production environment, you could simulate your insert / update workload by running SQL Query Stress. Do that before adding the index to get a baseline, and then after to see how much slower it is, and whether that change is acceptable.



        In addition to additional overhead for your DUI operations, another consideration is blocking. You might have different blocking patterns than you're used to, since some SELECT queries will be using the new index, and inserts / updates will have to take locks on that index and the clustered index.



        I only point this out to make the point that DUI "overhead" is not the only consideration. Adding indexes can often help with blocking, since SELECT queries on the narrower NC index won't be blocked by updates to other columns in the clustered index.




        Without knowing anything about your table, here's a quick walkthrough of what the SQL Query Stress approach might look like. I'll set up a "LogTable" in a new database:



        USE [master];
        GO

        CREATE DATABASE [232113];
        GO

        ALTER DATABASE [232113] SET RECOVERY SIMPLE WITH NO_WAIT;
        GO

        USE [232113];
        GO

        CREATE TABLE dbo.LogTable
        (
        Id INT PRIMARY KEY IDENTITY(1,1),
        Col1 DATETIME NOT NULL,
        Col2 CHAR(4) NOT NULL
        );


        Then I use these two queries to simulate the INSERT / UPDATE workload:



        -- insert a row
        INSERT INTO dbo.LogTable
        (Col1, Col2)
        VALUES
        (GETDATE(), 'val2');

        -- update a random row
        UPDATE dbo.LogTable
        SET Col2 = 'val3'
        WHERE Id = (SELECT TOP (1) Id
        FROM dbo.LogTable
        ORDER BY NEWID());


        Then I run SQL Query Stress over 6 threads, 250 iterations per thread, with a 100 ms delay between each execution. This completes in about 25 seconds with just the clustered index in place.



        screenshot of SQL Query Stress results



        Now I'll create a nonclustered index on Col2, which is affected by both the inserts and the updates:



        CREATE NONCLUSTERED INDEX IX_Col2 ON dbo.LogTable (Col2);


        Running the test again, it took basically the same amount of time (25 seconds). Notice that the logical reads went up, so there is some cost here (it just didn't affect the overall duration).



        screenshot of SQL Query Stress results



        Of course, this is a very simple case, with no other activity on the "server" (my laptop), so the difference is minimal. But hopefully it demonstrates the concept.






        share|improve this answer













        If you have a non-production environment, you could simulate your insert / update workload by running SQL Query Stress. Do that before adding the index to get a baseline, and then after to see how much slower it is, and whether that change is acceptable.



        In addition to additional overhead for your DUI operations, another consideration is blocking. You might have different blocking patterns than you're used to, since some SELECT queries will be using the new index, and inserts / updates will have to take locks on that index and the clustered index.



        I only point this out to make the point that DUI "overhead" is not the only consideration. Adding indexes can often help with blocking, since SELECT queries on the narrower NC index won't be blocked by updates to other columns in the clustered index.




        Without knowing anything about your table, here's a quick walkthrough of what the SQL Query Stress approach might look like. I'll set up a "LogTable" in a new database:



        USE [master];
        GO

        CREATE DATABASE [232113];
        GO

        ALTER DATABASE [232113] SET RECOVERY SIMPLE WITH NO_WAIT;
        GO

        USE [232113];
        GO

        CREATE TABLE dbo.LogTable
        (
        Id INT PRIMARY KEY IDENTITY(1,1),
        Col1 DATETIME NOT NULL,
        Col2 CHAR(4) NOT NULL
        );


        Then I use these two queries to simulate the INSERT / UPDATE workload:



        -- insert a row
        INSERT INTO dbo.LogTable
        (Col1, Col2)
        VALUES
        (GETDATE(), 'val2');

        -- update a random row
        UPDATE dbo.LogTable
        SET Col2 = 'val3'
        WHERE Id = (SELECT TOP (1) Id
        FROM dbo.LogTable
        ORDER BY NEWID());


        Then I run SQL Query Stress over 6 threads, 250 iterations per thread, with a 100 ms delay between each execution. This completes in about 25 seconds with just the clustered index in place.



        screenshot of SQL Query Stress results



        Now I'll create a nonclustered index on Col2, which is affected by both the inserts and the updates:



        CREATE NONCLUSTERED INDEX IX_Col2 ON dbo.LogTable (Col2);


        Running the test again, it took basically the same amount of time (25 seconds). Notice that the logical reads went up, so there is some cost here (it just didn't affect the overall duration).



        screenshot of SQL Query Stress results



        Of course, this is a very simple case, with no other activity on the "server" (my laptop), so the difference is minimal. But hopefully it demonstrates the concept.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 14 at 13:00









        Josh DarnellJosh Darnell

        6,97022140




        6,97022140



























            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%2f232113%2fhow-to-determine-the-cost-of-index-creation%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