SQL Server Efficiently dropping a group of rows with millions and millions of rows

前端 未结 13 573
遇见更好的自我
遇见更好的自我 2021-02-04 12:26

I recently asked this question: MS SQL share identity seed amongst tables (Many people wondered why)

I have the following layout of a table:

Table: Star

13条回答
  •  悲哀的现实
    2021-02-04 13:21

    As Cade pointed out, adding a table for each category is manually partitioning the data, without the benefits of the unified access.

    There will never be any deletions for millions of rows that happen as fast as dropping a table, without the use of partitions.

    Therefore, it seems like using a separate table for each category may be a valid solution. However, since you've stated that some of these categories are kept, and some are deleted, here is a solution:

    1. Create a new stars table for each new category.
    2. Wait for the time period to expire where you decide whether the stars for the category are kept or not.
    3. Roll the records into the main stars table if you plan on keeping them.
    4. Drop the table.

    This way, you will have a finite number of tables, depending on the rate you add categories and the time period where you decide if you want them or not.

    Ultimately, for the categories that you keep, you're doubling the work, but the extra work is distributed over time. Inserts to the end of the clustered index may be experienced less by the users than deletes from the middle. However, for those categories that you're not keeping, you're saving tons of time.

    Even if you're not technically saving work, perception is often the bigger issue.

提交回复
热议问题