Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old March 8th, 2006, 08:55 PM
db2udbgirl
Guest
 
Posts: n/a
Default select count(*) - Full table scan

If I perform a select count(*) from tred.order_delivery query will it
internally perform a full table scan to determine the row count for the
following scenario
case 1: There is a primary key on a column
case 2: There is a compound key on 1 columns col1, col2
case 3: No primary key in the table (Just for my education)




  #2  
Old March 8th, 2006, 11:45 PM
Joe Weinstein
Guest
 
Posts: n/a
Default Re: select count(*) - Full table scan



db2udbgirl wrote:[color=blue]
> If I perform a select count(*) from tred.order_delivery query will it
> internally perform a full table scan to determine the row count for the
> following scenario
> case 1: There is a primary key on a column
> case 2: There is a compound key on 1 columns col1, col2
> case 3: No primary key in the table (Just for my education)[/color]

Usually, if there is any unique index on a table,
the DBMS can avoid a table scan, else it has to.

  #3  
Old March 9th, 2006, 12:25 AM
Mark A
Guest
 
Posts: n/a
Default Re: select count(*) - Full table scan

> db2udbgirl wrote:[color=blue][color=green]
>> If I perform a select count(*) from tred.order_delivery query will it
>> internally perform a full table scan to determine the row count for the
>> following scenario
>> case 1: There is a primary key on a column
>> case 2: There is a compound key on 1 columns col1, col2
>> case 3: No primary key in the table (Just for my education)[/color]
>
>"Joe Weinstein" <joeNOSPAM@bea.com> wrote in message
>news:440F68A7.9080803@bea.com...
> Usually, if there is any unique index on a table,
> the DBMS can avoid a table scan, else it has to.
>[/color]

Not exactly. There is one index row for each table row, so any index will
do, unique or non-unique. DB2 will likely choose the smallest index and
count the index rows. If the table is small enough, DB2 may count the table
rows and bypass the index. Try an explain with each scenario.


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.