Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6038305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:12:01+00:00 2026-05-23T06:12:01+00:00

I have a query as follows; SELECT COUNT(Id) FROM Table The table contains 33

  • 0

I have a query as follows;

 SELECT COUNT(Id) FROM Table

The table contains 33 million records – it contains a primary key on Id and no other indices.

The query takes 30 seconds.

The actual execution plan shows it uses a clustered index scan.

We have analysed the table and found it isn’t fragmented using the first query shown in this link: http://sqlserverpedia.com/wiki/Index_Maintenance.

Any ideas as to why this query is so slow and how to fix it.

The Table Definition:

 CREATE TABLE [dbo].[DbConversation](
[ConversationID] [int] IDENTITY(1,1) NOT NULL,
[ConversationGroupID] [int] NOT NULL,
[InsideIP] [uniqueidentifier] NOT NULL,
[OutsideIP] [uniqueidentifier] NOT NULL,
[ServerPort] [int] NOT NULL,
[BytesOutbound] [bigint] NOT NULL,
[BytesInbound] [bigint] NOT NULL,
[ServerOutside] [bit] NOT NULL,
[LastFlowTime] [datetime] NOT NULL,
[LastClientPort] [int] NOT NULL,
[Protocol] [tinyint] NOT NULL,
[TypeOfService] [tinyint] NOT NULL,
  CONSTRAINT [PK_Conversation_1] PRIMARY KEY CLUSTERED 
 (
[ConversationID] ASC
 )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
 ) ON [PRIMARY]
 GO

One thing I have noticed is the database is set to grow in 1Mb chunks.

It’s a live system so we restricted in what we can play with – any ideas?

UPDATE:

OK – we’ve improved performance in the actual query of interest by adding new non-clustered indices on appropriate columns so it’s not a critical issue anymore.

SELECT COUNT is still slow though – tried it with NOLOCK hints – no difference.

We’re all thinking it’s something to do with the Autogrowth set to 1Mb rather than a larger number, but surprised it has this effect. Can MDF fragmentation on the disk be a possible cause?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T06:12:02+00:00Added an answer on May 23, 2026 at 6:12 am

    Is this a frequently read/inserted/updated table? Is there update/insert activity concurrent with your select?

    My guess is the delay is due to contention.

    I’m able to run a count on 189m rows in 17 seconds on my dev server, but there’s nothing else hitting that table.

    If you aren’t too worried about contention or absolute accuracy you can do:

    exec sp_spaceused 'MyTableName' which will give a count based on meta-data.

    If you want a more exact count but don’t necessarily care if it reflect concurrent DELETE or INSERT activity you can do your current query with a NOLOCK hint:

    SELECT COUNT(id) FROM MyTable WITH (NOLOCK) which will not get row-level locks for your query and should run faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL query that goes as follows SELECT count(`clicks`.`user_id`) as total, `users`.`fullname`
I am searching for records in a table as follows: SELECT Id, Name FROM
So I have a SQL Query as Follows SELECT P.Date, P.CategoryName, P.ProductName, SUM(Quantity) Quantity,
I have a query on my database as such: SELECT * FROM expenses WHERE
I have a troublesome MySQL query as follows: SELECT camera_id, ((avg(low_price) + avg(high_price)) /
I have this SQL query: SELECT c.id as ID, c.class_name as CLASS, COUNT(e.student_id) AS
I have the follow Linq query ... which executes correctly: from t in Tasks
I have a query where I wish to retrieve the oldest X records. At
I have a query that originally looks like this: select c.Id, c.Name, c.CountryCode, c.CustomerNumber,
I have this query in sql server 2000: select pwdencrypt('AAAA') which outputs an encrypted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.