Thread: MVCC & indexes?

MVCC & indexes?

From
Ivan Voras
Date:
Ok, so MVCC is the best thing since a guy put a round stone on a stick
and called it "the wheel", but I've seen several references on this list
about "indexes not being under MVCC" - at least that's how I read it,
the original posts were explaining why indexes can't be used for solving
MIN()/MAX()/COUNT() aggregates. Is this correct?

In particular, I'm trying to find out is there (b)locking involved when
concurrently updating and/or inserting records in an indexed table. My
guess is that, since PG does copy+delete on updating, even updating a
non-indexed field will require fixups in the index tree (to point to the
new record) and thus (b)locking.



Re: MVCC & indexes?

From
Alvaro Herrera
Date:
Ivan Voras wrote:
> Ok, so MVCC is the best thing since a guy put a round stone on a stick
> and called it "the wheel", but I've seen several references on this list
> about "indexes not being under MVCC" - at least that's how I read it,
> the original posts were explaining why indexes can't be used for solving
> MIN()/MAX()/COUNT() aggregates. Is this correct?
>
> In particular, I'm trying to find out is there (b)locking involved when
> concurrently updating and/or inserting records in an indexed table. My
> guess is that, since PG does copy+delete on updating, even updating a
> non-indexed field will require fixups in the index tree (to point to the
> new record) and thus (b)locking.

Well, there certainly is locking involved in inserting index entries,
but it's more fine-grained than you seem to think.  Only one page of the
index is locked at any time, resulting in that typically there's very
little blocking involved.  Two processes can be inserting into the same
index concurrently (btree and GiST indexes at least; GiST only gained
concurrency in a recent release, I don't remember if it was 8.0 or 8.1).

--
Alvaro Herrera                                http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

Re: MVCC & indexes?

From
mark@mark.mielke.cc
Date:
On Tue, Oct 31, 2006 at 10:55:40PM +0100, Ivan Voras wrote:
> Ok, so MVCC is the best thing since a guy put a round stone on a stick
> and called it "the wheel", but I've seen several references on this list
> about "indexes not being under MVCC" - at least that's how I read it,
> the original posts were explaining why indexes can't be used for solving
> MIN()/MAX()/COUNT() aggregates. Is this correct?

> In particular, I'm trying to find out is there (b)locking involved when
> concurrently updating and/or inserting records in an indexed table. My
> guess is that, since PG does copy+delete on updating, even updating a
> non-indexed field will require fixups in the index tree (to point to the
> new record) and thus (b)locking.

Short bits of blocking. The PostgreSQL index 'problem', is that indexes
are conservative. They only guarantee to return at least as much data as
you should see. They cannot be used to limit what you see to only as much
as you should see.

Cheers,
mark

--
mark@mielke.cc / markm@ncf.ca / markm@nortel.com     __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   |
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

  One ring to rule them all, one ring to find them, one ring to bring them all
                       and in the darkness bind them...

                           http://mark.mielke.cc/


Re: MVCC & indexes?

From
Ivan Voras
Date:
Alvaro Herrera wrote:

> Well, there certainly is locking involved in inserting index entries,
> but it's more fine-grained than you seem to think.  Only one page of the
> index is locked at any time, resulting in that typically there's very
> little blocking involved.  Two processes can be inserting into the same
> index concurrently (btree and GiST indexes at least; GiST only gained
> concurrency in a recent release, I don't remember if it was 8.0 or 8.1).

Thank you, this was the bit I was missing. In retrospect, I don't really
know how I came to conclusion the whole index was being locked :(