Re: Is there any way to optimize count(*)
From: David Browne (meat_at_hotmail.com)
Date: 07/06/04
- Next message: Wayne Snyder: "Re: VARCHAR to INT"
- Previous message: Narayana Vyas Kondreddi: "Re: SQL views"
- In reply to: Casper Hornstrup: "Is there any way to optimize count(*)"
- Next in thread: Adam Machanic: "Re: Is there any way to optimize count(*)"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 6 Jul 2004 08:20:38 -0500
"Casper Hornstrup" <msdn@csite.com> wrote in message
news:%23OFhco1YEHA.3128@TK2MSFTNGP09.phx.gbl...
> I do paging on a table with products. Selecting a page in an resultset is
> fast (about 20ms).
> Selecting the total number of results in the resultset is however very
slow.
> SELECT COUNT(*) FROM Product WHERE ...
> This takes 2 seconds to perform. Can I do something to optimize this?
>
Check the execution plan.
If all of the columns referenced in the WHERE clause are in an index, then
SELECT COUNT(*) WHERE should be pretty cheap. Otherwise it will require a
table scan or an index scan followed by bookmark lookups.
David
- Next message: Wayne Snyder: "Re: VARCHAR to INT"
- Previous message: Narayana Vyas Kondreddi: "Re: SQL views"
- In reply to: Casper Hornstrup: "Is there any way to optimize count(*)"
- Next in thread: Adam Machanic: "Re: Is there any way to optimize count(*)"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|