Re: does "select count(*) from mytable" always do a seq

From: Pierre-Frédéric Caillaud <lists(at)boutiquenumerique(dot)com>
To: alex(at)neteconomist(dot)com, "Scott Ribe" <scott_ribe(at)killerbytes(dot)com>
Cc: Postgresql-General <pgsql-general(at)postgresql(dot)org>
Subject: Re: does "select count(*) from mytable" always do a seq
Date: 2005-01-09 00:34:04
Message-ID: opska7u2ixcq72hf@musicbox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> (The example is really count(pkey) because count(*) is always going to
> do a seq scan I reckon - and could probably never use an index).

postgres knows that count(*) is just "count the rows", you can use
count(1), it makes no difference...

>
> Alex Turner
> NetEconomist
>
>
> On Fri, 07 Jan 2005 11:17:32 -0700, Scott Ribe
> <scott_ribe(at)killerbytes(dot)com> wrote:
>> > I guess what I"m really asking is why can't you run aggregates over
>> an index?
>>
>> It's got to do with MVCC and transaction consistency. Running count(*)
>> or an
>> aggregate function on an index could include records that should not be
>> visible to your current transaction.
>>
>> --
>> Scott Ribe
>> scott_ribe(at)killerbytes(dot)com
>> http://www.killerbytes.com/
>> (303) 665-7007 voice
>>
>> ---------------------------(end of broadcast)---------------------------
>> TIP 8: explain analyze is your friend
>>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2005-01-09 02:45:17 general list
Previous Message Pierre-Frédéric Caillaud 2005-01-09 00:32:27 Re: PYTHON, ODBC