Re: does "select count(*) from mytable" always do a seq - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: does "select count(*) from mytable" always do a seq
Date
Msg-id 20050110163446.GA30793@wolff.to
Whole thread Raw
In response to Re: does "select count(*) from mytable" always do a seq  (Alex Turner <armtuk@gmail.com>)
Responses Re: does "select count(*) from mytable" always do a seq
List pgsql-general
On Mon, Jan 10, 2005 at 10:26:46 -0500,
  Alex Turner <armtuk@gmail.com> wrote:
> Forgive my ignorance, but I'm still learning about much of this stuff.
>  If you perform:
>
> select an_id, int_value from my_table where int_value>400;
>
> The table has an index on int_value and there are enough rows to
> warrant using it.  Doesn't the database perform in index scan on
> int_value followed by a retrieve for the datablocks with relavent oids
> to get the an_id field?

I don't think that oids are used in the process, but if the planner thinks
an index scan would be better it will use one.

> If another transaction has inserted rows into this table, won't the
> index have been updated, and contain new row references?  Does this
> imply that the database must retrieve the row information to determine
> if the row is a row from a different transaction?

When doing an index scan, the heap tuples still need to be checked for
visibility to the current transaction.

pgsql-general by date:

Previous
From: Sven Willenberger
Date:
Subject: Re: handing created and updated fields
Next
From: Brendan Jurd
Date:
Subject: Function for retreiving datatype