What is the appropriate index architecture when forced to implement IsDeleted (soft deletes)?Can filtered indexes help improve queries that are based on a time entered or should this be avoided?Clustered vs Nonclustered IndexUnused Indexes - Consider Primary Key Constraint Supporting Indexes?Question about non-clustered index storage in SQL ServerIndex not making execution faster, and in some cases is slowing down the query. Why is it so?Should I remove this clustered index?what if all the non clustered indexes on my table were filtered indexes?What is the formal definition of a Primary Index and Primary Key?Would a nonclustered index on the primary key speed up deletes and prevent deadlocks?When all you indexes have included all the other columns, do you still have the penalty for a wide clustered index?

Is there really no use for MD5 anymore?

Magical attacks and overcoming damage resistance

Island of Knights, Knaves and Spies

What does "function" actually mean in music?

How to keep bees out of canned beverages?

What to do with someone that cheated their way through university and a PhD program?

Double-nominative constructions and “von”

How important is it that $TERM is correct?

How to not starve gigantic beasts

What's the difference between using dependency injection with a container and using a service locator?

Why must Chinese maps be obfuscated?

How bug prioritization works in agile projects vs non agile

What *exactly* is electrical current, voltage, and resistance?

A strange hotel

Does the damage from the Absorb Elements spell apply to your next attack, or to your first attack on your next turn?

How long after the last departure shall the airport stay open for an emergency return?

Which big number is bigger?

How do I reattach a shelf to the wall when it ripped out of the wall?

Crossed out red box fitting tightly around image

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

Will I lose my paid in full property

How can I practically buy stocks?

How to have a sharp product image?

How do I check if a string is entirely made of the same substring?



What is the appropriate index architecture when forced to implement IsDeleted (soft deletes)?


Can filtered indexes help improve queries that are based on a time entered or should this be avoided?Clustered vs Nonclustered IndexUnused Indexes - Consider Primary Key Constraint Supporting Indexes?Question about non-clustered index storage in SQL ServerIndex not making execution faster, and in some cases is slowing down the query. Why is it so?Should I remove this clustered index?what if all the non clustered indexes on my table were filtered indexes?What is the formal definition of a Primary Index and Primary Key?Would a nonclustered index on the primary key speed up deletes and prevent deadlocks?When all you indexes have included all the other columns, do you still have the penalty for a wide clustered index?






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








15















Currently, we have an existing database and application that is fully functional. I do not have the ability to change the architecture at this point. Today, each table in the database has an "IsDeleted" NOT NULL BIT field with a default of '0'. When the application "deletes" data, it simply updates the IsDeleted flag to 1.



What I'm having trouble understanding is how the indexes on each of the tables should be structured. Right now, every query/join/etc always implements the IsDeleted check. It's a standard that our developers must follow. That being said, I'm trying to determine if all of my clustered primary key indexes on each of the tables need to be altered to include the primary key AND the IsDeleted BIT field. Also, since EVERY query/join/etc. must implement the IsDeleted check, is it an appropriate assumption that EVERY SINGLE index (non-clustered as well) should include the IsDeleted field as the first field of the index?



One other question I have is around filtered indexes. I understand that I could put filters on the indexes such as "WHERE IsDeleted = 0" to reduce the size of the indexes. However, since every join/query will have to implement the IsDeleted check, would that prevent the filtered index from being used (since the IsDeleted column is used in join/query)?



Remember, I do not have the ability to change the IsDeleted approach.










share|improve this question















migrated from serverfault.com Apr 18 at 14:11


This question came from our site for system and network administrators.













  • 6





    A big component of the architecture decision is the rough percentage of rows that will match IsDeleted = 0. If you're just now implementing it, and hardly any of the rows will have IsDeleted = 1 yet, then you don't have to worry nearly as much about it as, say, a 10-year-old system where 75% of the rows have IsDeleted = 1.

    – Brent Ozar
    Apr 18 at 13:34











  • Whilst not part of the question, I hope you don't have any 'users' in your system. a 'soft delete' function will likely not be acceptable in the post GDPR world.

    – Neil
    Apr 18 at 21:25

















15















Currently, we have an existing database and application that is fully functional. I do not have the ability to change the architecture at this point. Today, each table in the database has an "IsDeleted" NOT NULL BIT field with a default of '0'. When the application "deletes" data, it simply updates the IsDeleted flag to 1.



What I'm having trouble understanding is how the indexes on each of the tables should be structured. Right now, every query/join/etc always implements the IsDeleted check. It's a standard that our developers must follow. That being said, I'm trying to determine if all of my clustered primary key indexes on each of the tables need to be altered to include the primary key AND the IsDeleted BIT field. Also, since EVERY query/join/etc. must implement the IsDeleted check, is it an appropriate assumption that EVERY SINGLE index (non-clustered as well) should include the IsDeleted field as the first field of the index?



One other question I have is around filtered indexes. I understand that I could put filters on the indexes such as "WHERE IsDeleted = 0" to reduce the size of the indexes. However, since every join/query will have to implement the IsDeleted check, would that prevent the filtered index from being used (since the IsDeleted column is used in join/query)?



Remember, I do not have the ability to change the IsDeleted approach.










share|improve this question















migrated from serverfault.com Apr 18 at 14:11


This question came from our site for system and network administrators.













  • 6





    A big component of the architecture decision is the rough percentage of rows that will match IsDeleted = 0. If you're just now implementing it, and hardly any of the rows will have IsDeleted = 1 yet, then you don't have to worry nearly as much about it as, say, a 10-year-old system where 75% of the rows have IsDeleted = 1.

    – Brent Ozar
    Apr 18 at 13:34











  • Whilst not part of the question, I hope you don't have any 'users' in your system. a 'soft delete' function will likely not be acceptable in the post GDPR world.

    – Neil
    Apr 18 at 21:25













15












15








15








Currently, we have an existing database and application that is fully functional. I do not have the ability to change the architecture at this point. Today, each table in the database has an "IsDeleted" NOT NULL BIT field with a default of '0'. When the application "deletes" data, it simply updates the IsDeleted flag to 1.



What I'm having trouble understanding is how the indexes on each of the tables should be structured. Right now, every query/join/etc always implements the IsDeleted check. It's a standard that our developers must follow. That being said, I'm trying to determine if all of my clustered primary key indexes on each of the tables need to be altered to include the primary key AND the IsDeleted BIT field. Also, since EVERY query/join/etc. must implement the IsDeleted check, is it an appropriate assumption that EVERY SINGLE index (non-clustered as well) should include the IsDeleted field as the first field of the index?



One other question I have is around filtered indexes. I understand that I could put filters on the indexes such as "WHERE IsDeleted = 0" to reduce the size of the indexes. However, since every join/query will have to implement the IsDeleted check, would that prevent the filtered index from being used (since the IsDeleted column is used in join/query)?



Remember, I do not have the ability to change the IsDeleted approach.










share|improve this question
















Currently, we have an existing database and application that is fully functional. I do not have the ability to change the architecture at this point. Today, each table in the database has an "IsDeleted" NOT NULL BIT field with a default of '0'. When the application "deletes" data, it simply updates the IsDeleted flag to 1.



What I'm having trouble understanding is how the indexes on each of the tables should be structured. Right now, every query/join/etc always implements the IsDeleted check. It's a standard that our developers must follow. That being said, I'm trying to determine if all of my clustered primary key indexes on each of the tables need to be altered to include the primary key AND the IsDeleted BIT field. Also, since EVERY query/join/etc. must implement the IsDeleted check, is it an appropriate assumption that EVERY SINGLE index (non-clustered as well) should include the IsDeleted field as the first field of the index?



One other question I have is around filtered indexes. I understand that I could put filters on the indexes such as "WHERE IsDeleted = 0" to reduce the size of the indexes. However, since every join/query will have to implement the IsDeleted check, would that prevent the filtered index from being used (since the IsDeleted column is used in join/query)?



Remember, I do not have the ability to change the IsDeleted approach.







sql-server sql-server-2012 index






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 18 at 14:17









Philᵀᴹ

26k65691




26k65691










asked Apr 18 at 13:24







Jerad Skinner











migrated from serverfault.com Apr 18 at 14:11


This question came from our site for system and network administrators.









migrated from serverfault.com Apr 18 at 14:11


This question came from our site for system and network administrators.









  • 6





    A big component of the architecture decision is the rough percentage of rows that will match IsDeleted = 0. If you're just now implementing it, and hardly any of the rows will have IsDeleted = 1 yet, then you don't have to worry nearly as much about it as, say, a 10-year-old system where 75% of the rows have IsDeleted = 1.

    – Brent Ozar
    Apr 18 at 13:34











  • Whilst not part of the question, I hope you don't have any 'users' in your system. a 'soft delete' function will likely not be acceptable in the post GDPR world.

    – Neil
    Apr 18 at 21:25












  • 6





    A big component of the architecture decision is the rough percentage of rows that will match IsDeleted = 0. If you're just now implementing it, and hardly any of the rows will have IsDeleted = 1 yet, then you don't have to worry nearly as much about it as, say, a 10-year-old system where 75% of the rows have IsDeleted = 1.

    – Brent Ozar
    Apr 18 at 13:34











  • Whilst not part of the question, I hope you don't have any 'users' in your system. a 'soft delete' function will likely not be acceptable in the post GDPR world.

    – Neil
    Apr 18 at 21:25







6




6





A big component of the architecture decision is the rough percentage of rows that will match IsDeleted = 0. If you're just now implementing it, and hardly any of the rows will have IsDeleted = 1 yet, then you don't have to worry nearly as much about it as, say, a 10-year-old system where 75% of the rows have IsDeleted = 1.

– Brent Ozar
Apr 18 at 13:34





A big component of the architecture decision is the rough percentage of rows that will match IsDeleted = 0. If you're just now implementing it, and hardly any of the rows will have IsDeleted = 1 yet, then you don't have to worry nearly as much about it as, say, a 10-year-old system where 75% of the rows have IsDeleted = 1.

– Brent Ozar
Apr 18 at 13:34













Whilst not part of the question, I hope you don't have any 'users' in your system. a 'soft delete' function will likely not be acceptable in the post GDPR world.

– Neil
Apr 18 at 21:25





Whilst not part of the question, I hope you don't have any 'users' in your system. a 'soft delete' function will likely not be acceptable in the post GDPR world.

– Neil
Apr 18 at 21:25










4 Answers
4






active

oldest

votes


















12














The easiest approach here is to leave your keys and clustered indexes alone, and use filtered indexes for your non-clustered indexes.



Additionally you can migrate some large tables to partitioned heaps or partitioned clustered-columnstores (SQL Server 2016+), leaving the primary key and unique indexes un-partitioned. This would enable you to push the non-key columns for IsDeleted rows to a seperate data structure, which could additionally be compressed differently or stored on a different filegroup.



And make sure the developers use a literal instead of a parameter to filter the IsDeleted rows out. With a parameter SQL Server has to use the same query plan for both cases.



EG



SELECT ... WHERE ... AND IsDeleted=0


And not:



SELECT ... WHERE ... AND IsDeleted=@IsDeleted


Using a paramter will prevent use of filtered index, and can get you into trouble with parameter sniffing.






share|improve this answer

























  • Given the ubiquity and importance of the IsDeleted column, regardless of the physical storage it would probably make sense to expose the data through two views (optionally in different schemas), solving both the parameterization issue and making mistakes with accessing data that shouldn't have been accessed less likely. Accessing the base data is only relevant for the rare cases where deleted and non-deleted data need to be combined somehow, and when rows actually need to be switched to "deleted".

    – Jeroen Mostert
    Apr 19 at 11:29











  • @JeroenMostert good advice. RLS can also be used here, or something like EF Core Global Query Filters. docs.microsoft.com/en-us/ef/core/querying/filters

    – David Browne - Microsoft
    Apr 19 at 12:17


















8














This might be an unpopular opinion, but I don't think there is a "do this everywhere" / one size fits all answer to your question.



If you have queries that are scanning lots of IsDeleted rows for no reason, one solution is to create a filtered, nonclustered index to satisfy that query.



Another option is to create an indexed view that could be leveraged by a number of different queries, which is filtered to just the non-deleted rows. This could be especially useful on Enterprise Edition, where automatic indexed view matching works without providing a NOEXPAND hint.



For small tables, or tables that are read heavily, adding filtered nonclustered indexes or views or anything really might just be adding unnecessary overhead to your database.






share|improve this answer






























    2














    Under the reasonable assumption that deletes are rare, no changes to the indices is an appropriate solution.



    I found that sooner or later one must query for references to deleted rows, and the rows being in the indices is suddenly very worth it.



    Please note that unless you are using views, you have to edit all of your queries to include the filters anyway.






    share|improve this answer






























      0














      I have seen a system where the IS_DELETED flag is either 0 or the value of the PK. In other systems it was the negative of the PK.



      Since most queries retrieved values by the "natural" or business (sometimes multi-field) key, they never queried by PK except through joins; but they did always add an AND IS_DELETED = 0 at the end for the main table and for any joined tables.



      This system also had an audit table for every transactional table that tracked changes; and the application had a feature to display all the data changes including the deleted data.






      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%2f235169%2fwhat-is-the-appropriate-index-architecture-when-forced-to-implement-isdeleted-s%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown
























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        12














        The easiest approach here is to leave your keys and clustered indexes alone, and use filtered indexes for your non-clustered indexes.



        Additionally you can migrate some large tables to partitioned heaps or partitioned clustered-columnstores (SQL Server 2016+), leaving the primary key and unique indexes un-partitioned. This would enable you to push the non-key columns for IsDeleted rows to a seperate data structure, which could additionally be compressed differently or stored on a different filegroup.



        And make sure the developers use a literal instead of a parameter to filter the IsDeleted rows out. With a parameter SQL Server has to use the same query plan for both cases.



        EG



        SELECT ... WHERE ... AND IsDeleted=0


        And not:



        SELECT ... WHERE ... AND IsDeleted=@IsDeleted


        Using a paramter will prevent use of filtered index, and can get you into trouble with parameter sniffing.






        share|improve this answer

























        • Given the ubiquity and importance of the IsDeleted column, regardless of the physical storage it would probably make sense to expose the data through two views (optionally in different schemas), solving both the parameterization issue and making mistakes with accessing data that shouldn't have been accessed less likely. Accessing the base data is only relevant for the rare cases where deleted and non-deleted data need to be combined somehow, and when rows actually need to be switched to "deleted".

          – Jeroen Mostert
          Apr 19 at 11:29











        • @JeroenMostert good advice. RLS can also be used here, or something like EF Core Global Query Filters. docs.microsoft.com/en-us/ef/core/querying/filters

          – David Browne - Microsoft
          Apr 19 at 12:17















        12














        The easiest approach here is to leave your keys and clustered indexes alone, and use filtered indexes for your non-clustered indexes.



        Additionally you can migrate some large tables to partitioned heaps or partitioned clustered-columnstores (SQL Server 2016+), leaving the primary key and unique indexes un-partitioned. This would enable you to push the non-key columns for IsDeleted rows to a seperate data structure, which could additionally be compressed differently or stored on a different filegroup.



        And make sure the developers use a literal instead of a parameter to filter the IsDeleted rows out. With a parameter SQL Server has to use the same query plan for both cases.



        EG



        SELECT ... WHERE ... AND IsDeleted=0


        And not:



        SELECT ... WHERE ... AND IsDeleted=@IsDeleted


        Using a paramter will prevent use of filtered index, and can get you into trouble with parameter sniffing.






        share|improve this answer

























        • Given the ubiquity and importance of the IsDeleted column, regardless of the physical storage it would probably make sense to expose the data through two views (optionally in different schemas), solving both the parameterization issue and making mistakes with accessing data that shouldn't have been accessed less likely. Accessing the base data is only relevant for the rare cases where deleted and non-deleted data need to be combined somehow, and when rows actually need to be switched to "deleted".

          – Jeroen Mostert
          Apr 19 at 11:29











        • @JeroenMostert good advice. RLS can also be used here, or something like EF Core Global Query Filters. docs.microsoft.com/en-us/ef/core/querying/filters

          – David Browne - Microsoft
          Apr 19 at 12:17













        12












        12








        12







        The easiest approach here is to leave your keys and clustered indexes alone, and use filtered indexes for your non-clustered indexes.



        Additionally you can migrate some large tables to partitioned heaps or partitioned clustered-columnstores (SQL Server 2016+), leaving the primary key and unique indexes un-partitioned. This would enable you to push the non-key columns for IsDeleted rows to a seperate data structure, which could additionally be compressed differently or stored on a different filegroup.



        And make sure the developers use a literal instead of a parameter to filter the IsDeleted rows out. With a parameter SQL Server has to use the same query plan for both cases.



        EG



        SELECT ... WHERE ... AND IsDeleted=0


        And not:



        SELECT ... WHERE ... AND IsDeleted=@IsDeleted


        Using a paramter will prevent use of filtered index, and can get you into trouble with parameter sniffing.






        share|improve this answer















        The easiest approach here is to leave your keys and clustered indexes alone, and use filtered indexes for your non-clustered indexes.



        Additionally you can migrate some large tables to partitioned heaps or partitioned clustered-columnstores (SQL Server 2016+), leaving the primary key and unique indexes un-partitioned. This would enable you to push the non-key columns for IsDeleted rows to a seperate data structure, which could additionally be compressed differently or stored on a different filegroup.



        And make sure the developers use a literal instead of a parameter to filter the IsDeleted rows out. With a parameter SQL Server has to use the same query plan for both cases.



        EG



        SELECT ... WHERE ... AND IsDeleted=0


        And not:



        SELECT ... WHERE ... AND IsDeleted=@IsDeleted


        Using a paramter will prevent use of filtered index, and can get you into trouble with parameter sniffing.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 18 at 20:53

























        answered Apr 18 at 14:48









        David Browne - MicrosoftDavid Browne - Microsoft

        12.8k733




        12.8k733












        • Given the ubiquity and importance of the IsDeleted column, regardless of the physical storage it would probably make sense to expose the data through two views (optionally in different schemas), solving both the parameterization issue and making mistakes with accessing data that shouldn't have been accessed less likely. Accessing the base data is only relevant for the rare cases where deleted and non-deleted data need to be combined somehow, and when rows actually need to be switched to "deleted".

          – Jeroen Mostert
          Apr 19 at 11:29











        • @JeroenMostert good advice. RLS can also be used here, or something like EF Core Global Query Filters. docs.microsoft.com/en-us/ef/core/querying/filters

          – David Browne - Microsoft
          Apr 19 at 12:17

















        • Given the ubiquity and importance of the IsDeleted column, regardless of the physical storage it would probably make sense to expose the data through two views (optionally in different schemas), solving both the parameterization issue and making mistakes with accessing data that shouldn't have been accessed less likely. Accessing the base data is only relevant for the rare cases where deleted and non-deleted data need to be combined somehow, and when rows actually need to be switched to "deleted".

          – Jeroen Mostert
          Apr 19 at 11:29











        • @JeroenMostert good advice. RLS can also be used here, or something like EF Core Global Query Filters. docs.microsoft.com/en-us/ef/core/querying/filters

          – David Browne - Microsoft
          Apr 19 at 12:17
















        Given the ubiquity and importance of the IsDeleted column, regardless of the physical storage it would probably make sense to expose the data through two views (optionally in different schemas), solving both the parameterization issue and making mistakes with accessing data that shouldn't have been accessed less likely. Accessing the base data is only relevant for the rare cases where deleted and non-deleted data need to be combined somehow, and when rows actually need to be switched to "deleted".

        – Jeroen Mostert
        Apr 19 at 11:29





        Given the ubiquity and importance of the IsDeleted column, regardless of the physical storage it would probably make sense to expose the data through two views (optionally in different schemas), solving both the parameterization issue and making mistakes with accessing data that shouldn't have been accessed less likely. Accessing the base data is only relevant for the rare cases where deleted and non-deleted data need to be combined somehow, and when rows actually need to be switched to "deleted".

        – Jeroen Mostert
        Apr 19 at 11:29













        @JeroenMostert good advice. RLS can also be used here, or something like EF Core Global Query Filters. docs.microsoft.com/en-us/ef/core/querying/filters

        – David Browne - Microsoft
        Apr 19 at 12:17





        @JeroenMostert good advice. RLS can also be used here, or something like EF Core Global Query Filters. docs.microsoft.com/en-us/ef/core/querying/filters

        – David Browne - Microsoft
        Apr 19 at 12:17













        8














        This might be an unpopular opinion, but I don't think there is a "do this everywhere" / one size fits all answer to your question.



        If you have queries that are scanning lots of IsDeleted rows for no reason, one solution is to create a filtered, nonclustered index to satisfy that query.



        Another option is to create an indexed view that could be leveraged by a number of different queries, which is filtered to just the non-deleted rows. This could be especially useful on Enterprise Edition, where automatic indexed view matching works without providing a NOEXPAND hint.



        For small tables, or tables that are read heavily, adding filtered nonclustered indexes or views or anything really might just be adding unnecessary overhead to your database.






        share|improve this answer



























          8














          This might be an unpopular opinion, but I don't think there is a "do this everywhere" / one size fits all answer to your question.



          If you have queries that are scanning lots of IsDeleted rows for no reason, one solution is to create a filtered, nonclustered index to satisfy that query.



          Another option is to create an indexed view that could be leveraged by a number of different queries, which is filtered to just the non-deleted rows. This could be especially useful on Enterprise Edition, where automatic indexed view matching works without providing a NOEXPAND hint.



          For small tables, or tables that are read heavily, adding filtered nonclustered indexes or views or anything really might just be adding unnecessary overhead to your database.






          share|improve this answer

























            8












            8








            8







            This might be an unpopular opinion, but I don't think there is a "do this everywhere" / one size fits all answer to your question.



            If you have queries that are scanning lots of IsDeleted rows for no reason, one solution is to create a filtered, nonclustered index to satisfy that query.



            Another option is to create an indexed view that could be leveraged by a number of different queries, which is filtered to just the non-deleted rows. This could be especially useful on Enterprise Edition, where automatic indexed view matching works without providing a NOEXPAND hint.



            For small tables, or tables that are read heavily, adding filtered nonclustered indexes or views or anything really might just be adding unnecessary overhead to your database.






            share|improve this answer













            This might be an unpopular opinion, but I don't think there is a "do this everywhere" / one size fits all answer to your question.



            If you have queries that are scanning lots of IsDeleted rows for no reason, one solution is to create a filtered, nonclustered index to satisfy that query.



            Another option is to create an indexed view that could be leveraged by a number of different queries, which is filtered to just the non-deleted rows. This could be especially useful on Enterprise Edition, where automatic indexed view matching works without providing a NOEXPAND hint.



            For small tables, or tables that are read heavily, adding filtered nonclustered indexes or views or anything really might just be adding unnecessary overhead to your database.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 18 at 14:52









            Josh DarnellJosh Darnell

            8,49822244




            8,49822244





















                2














                Under the reasonable assumption that deletes are rare, no changes to the indices is an appropriate solution.



                I found that sooner or later one must query for references to deleted rows, and the rows being in the indices is suddenly very worth it.



                Please note that unless you are using views, you have to edit all of your queries to include the filters anyway.






                share|improve this answer



























                  2














                  Under the reasonable assumption that deletes are rare, no changes to the indices is an appropriate solution.



                  I found that sooner or later one must query for references to deleted rows, and the rows being in the indices is suddenly very worth it.



                  Please note that unless you are using views, you have to edit all of your queries to include the filters anyway.






                  share|improve this answer

























                    2












                    2








                    2







                    Under the reasonable assumption that deletes are rare, no changes to the indices is an appropriate solution.



                    I found that sooner or later one must query for references to deleted rows, and the rows being in the indices is suddenly very worth it.



                    Please note that unless you are using views, you have to edit all of your queries to include the filters anyway.






                    share|improve this answer













                    Under the reasonable assumption that deletes are rare, no changes to the indices is an appropriate solution.



                    I found that sooner or later one must query for references to deleted rows, and the rows being in the indices is suddenly very worth it.



                    Please note that unless you are using views, you have to edit all of your queries to include the filters anyway.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Apr 18 at 17:03









                    JoshuaJoshua

                    1736




                    1736





















                        0














                        I have seen a system where the IS_DELETED flag is either 0 or the value of the PK. In other systems it was the negative of the PK.



                        Since most queries retrieved values by the "natural" or business (sometimes multi-field) key, they never queried by PK except through joins; but they did always add an AND IS_DELETED = 0 at the end for the main table and for any joined tables.



                        This system also had an audit table for every transactional table that tracked changes; and the application had a feature to display all the data changes including the deleted data.






                        share|improve this answer



























                          0














                          I have seen a system where the IS_DELETED flag is either 0 or the value of the PK. In other systems it was the negative of the PK.



                          Since most queries retrieved values by the "natural" or business (sometimes multi-field) key, they never queried by PK except through joins; but they did always add an AND IS_DELETED = 0 at the end for the main table and for any joined tables.



                          This system also had an audit table for every transactional table that tracked changes; and the application had a feature to display all the data changes including the deleted data.






                          share|improve this answer

























                            0












                            0








                            0







                            I have seen a system where the IS_DELETED flag is either 0 or the value of the PK. In other systems it was the negative of the PK.



                            Since most queries retrieved values by the "natural" or business (sometimes multi-field) key, they never queried by PK except through joins; but they did always add an AND IS_DELETED = 0 at the end for the main table and for any joined tables.



                            This system also had an audit table for every transactional table that tracked changes; and the application had a feature to display all the data changes including the deleted data.






                            share|improve this answer













                            I have seen a system where the IS_DELETED flag is either 0 or the value of the PK. In other systems it was the negative of the PK.



                            Since most queries retrieved values by the "natural" or business (sometimes multi-field) key, they never queried by PK except through joins; but they did always add an AND IS_DELETED = 0 at the end for the main table and for any joined tables.



                            This system also had an audit table for every transactional table that tracked changes; and the application had a feature to display all the data changes including the deleted data.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Apr 19 at 4:31









                            Rick RykerRick Ryker

                            1413




                            1413



























                                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%2f235169%2fwhat-is-the-appropriate-index-architecture-when-forced-to-implement-isdeleted-s%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

                                How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

                                What if the end-user didn't have the required library?What is setup.py?What is a clean, pythonic way to have multiple constructors in Python?What does Ruby have that Python doesn't, and vice versa?What is the reason for having '//' in Python?How do I create a namespace package in Python?How to package shared objects that python modules depend on?setuptools vs. distutils: why is distutils still a thing?Navigation in Windows 10 vs code not going to virtualenv library when the same library is installed at user levelPython create package for local usePackaging a project that uses multiple python versionsWhy is permission denied on pip install except for when “--user” is included at end of command?

                                Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos