August 18, 2010 at 1:39 pm
Hi Guys,
I have a table with 25M+ records, i tried doing query like as simple as this:
SELECT COUNT(id)
FROM MyTable
WHERE clientId = @clientId
If the @clientId supplied exists in MyTable table, the query will return the row count quickly like less than 2 seconds at least BUT if it doesn't it just keeps on reader until like 15minutes+ and have to stop it.
I just want to check if the client id exist on MyTable or not.
Any thought?
August 19, 2010 at 8:17 am
LutzM (8/18/2010)
If you only need to know if a client id exists use EXISTS instead of COUNT(). See Gail's related blog[/url].Side note: Is there any index on clientId to support the query?
Thank you for the response LutzM.
I tried EXISTS but it was the same. ClientId is a reference to Client table of some sort from MyTable.
August 19, 2010 at 9:53 am
I think you might want to respond to Lutz's side note? Is the ClientId Column Indexed appropriately?
August 19, 2010 at 8:30 pm
I don't think the ClientId column is indexed, the only indexed column that I see is the ID of MyTable and this is already an existing design when I came in.
August 20, 2010 at 4:05 am
If the ClientId column isn't indexed you will end up with a table scan causing bad performance. If you're allowed to, add the ClientId (nonclustered) index and see if it helps.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply