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 8309277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:04:05+00:00 2026-06-08T19:04:05+00:00

I am having some performance issues with a query I am running in SQL

  • 0

I am having some performance issues with a query I am running in SQL Server 2008. I have the following query:

Query1:

 SELECT GroupID, COUNT(*) AS TotalRows FROM Table1 
    INNER JOIN (
        SELECT Column1 FROM Table2 WHERE GroupID = @GroupID
    ) AS Table2
     ON Table2.Column1 = Table1.Column1 
WHERE CONTAINS(Table1.*, @Word) GROUP BY GroupID

Table1 contains about 500,000 rows. Table2 contains about 50,000, but will eventually contain millions. Playing around with the query, I found that re-writing the query as follows will reduce the execution time of the query to under 1 second.

Query 2:

SELECT GroupID FROM Table1 
    INNER JOIN (
        SELECT Column1 FROM Table2 WHERE GroupID = @GroupID
    ) AS Table2 ON Table2.Column1 = Table1.Column1 
WHERE CONTAINS(Table1.*, @Word)

What I do not understand is it is a simple count query. If I execute the following query on Table 1, it returns in < 1 s:

Query 3:

SELECT Count(*) FROM Table1

This query returns around 500,000 as the result.

However, the Original query (Query 1) mentioned above only returns a count of 50,000 and takes 3s to execute even though simply removing the GROUP BY (Query 2) reduces the execution time to < 1s.

I do not believe this is an indexing issue as I already have indexes on the appropriate columns. Any help would be very appreciated.

  • 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-06-08T19:04:07+00:00Added an answer on June 8, 2026 at 7:04 pm

    Performing a simple COUNT(*) FROM table can do a much more efficient scan of the clustered index, since it doesn’t have to care about any filtering, joining, grouping, etc. The queries that include full-text search predicates and mysterious subqueries have to do a lot more work. The count is not the most expensive part there – I bet they’re still relatively slow if you leave the count out but leave the group by in, e.g.:

    SELECT GroupID FROM Table1 
        INNER JOIN (
            SELECT Column1 FROM Table2 WHERE GroupID = @GroupID
        ) AS Table2 ON Table2.Column1 = Table1.Column1 
    WHERE CONTAINS(Table1.*, @Word)
    GROUP BY GroupID;
    

    Looking at the provided actual execution plan in the free SQL Sentry Plan Explorer*, I see this:

    enter image description here

    And this:

    enter image description here

    Which lead me to believe you should:

    1. Update the statistics on both Inventory and A001_Store_Inventory so that the optimizer can get a better rowcount estimate (which could lead to a better plan shape).
    2. Ensure that Inventory.ItemNumber and A001_Store_Inventory.ItemNumber are the same data type to avoid an implicit conversion.

    (*) disclaimer: I work for SQL Sentry.

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

Sidebar

Related Questions

I have been investigating some performance issues with my database (SQL Server 2008). SQL
I am having noticing some performance issues on my MySQL Server. The slow query
We are having some major performance issues with SELECT queries out one of our
Hi I'm logging slow queries because we're having some performance issues and I have
We recently are having major performance related issues in our current SQL Server DB.
I'm having some performance issues in a rails project (running on rails 2.0.5), for
I am having some performance issue of linq compiled query. using (var txn =
I'm having some performance issues calling CGContextDrawLayerAtPoint in iOS 4 that didn't seem to
I'm having some serious performance issues with a multi-million row table that I feel
I'm having some performance issues since a DB was moved from SQL2000 to SQL2008.

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.