Slow distinct query in SQL Server over large dataset

前端 未结 10 2609
情深已故
情深已故 2021-02-14 00:27

We\'re using SQL Server 2005 to track a fair amount of constantly incoming data (5-15 updates per second). We noticed after it has been in production for a couple months that on

10条回答
  •  死守一世寂寞
    2021-02-14 00:56

    My first thought is statistics. To find last updated:

    SELECT
        name AS index_name, 
        STATS_DATE(object_id, index_id) AS statistics_update_date
    FROM
        sys.indexes 
    WHERE
        object_id = OBJECT_ID('MyTable');
    

    Edit: Stats are updated when indexes are rebuilt, which I see are not maintained

    My second thought is that is the index still there? The TOP query should still use an index. I've just tested on one of my tables with 57 million rows and both use the index.

提交回复
热议问题