“select count(id) from table” takes up to 30 minutes to calculate in SQL Azure

前端 未结 3 1391
野趣味
野趣味 2021-02-07 04:30

I have a database in SQL Azure which is not taking between 15 and 30 minutes to do a simple:

select count(id) from mytable

The database is abou

3条回答
  •  别跟我提以往
    2021-02-07 04:46

    Suggestion: try select count(*) instead: it might actually improve the response time:

    • http://www.sqlskills.com/blogs/paul/which-index-will-sql-server-use-to-count-all-rows/

    Also, have you done an "explain plan"?

    • http://azure.microsoft.com/blog/2011/12/15/sql-azure-management-portal-tips-and-tricks-part-ii/

    • http://social.technet.microsoft.com/wiki/contents/articles/1657.gaining-performance-insight-into-windows-azure-sql-database.aspx

    ============ UPDATE ============

    Thank you for getting the statistics.

    You're doing a full table scan of 2M rows - not good :(

    POSSIBLE WORKAROUND: query system table row_count instead:

    http://blogs.msdn.com/b/arunrakwal/archive/2012/04/09/sql-azure-list-of-tables-with-record-count.aspx

    select t.name ,s.row_count from sys.tables t
    join sys.dm_db_partition_stats s
    ON t.object_id = s.object_id
      and t.type_desc = 'USER_TABLE'
      and t.name not like '%dss%'
      and s.index_id = 1
    

提交回复
热议问题