Re: 'locking' the SELECTs based on indices... - Mailing list pgsql-sql

From Tom Lane
Subject Re: 'locking' the SELECTs based on indices...
Date
Msg-id 14024.1140634704@sss.pgh.pa.us
Whole thread Raw
In response to 'locking' the SELECTs based on indices...  (Mario Splivalo <mario.splivalo@mobart.hr>)
Responses Re: 'locking' the SELECTs based on indices...  (Mario Splivalo <mario.splivalo@mobart.hr>)
List pgsql-sql
Mario Splivalo <mario.splivalo@mobart.hr> writes:
> Now, when I do this from one connection (psql shell, for instance):

> [A]BEGIN TRANSACTION;
> [A]SELECT * FROM bla WHERE code_id = 1 FOR UPDATE;

> and then, from another psql i do:
> [B]SELECT * FROM bla WHERE code_id = 1 FOR UPDATE

> the second SELECT will wait untill I rollback or commit first
> transaction. That is cool. 

> But, if I do second SELECT like this:

> [C]SELECT * FROM bla WHERE code_id = 2 FOR UPDATE

> I will get the rows.

Well, of course.  Why would you want something different?  Why do you
think the table's indexes should have anything to do with it?

If you want a full-table lock then some form of LOCK TABLE seems like
the proper answer.  SELECT FOR UPDATE is designed to lock the specified
rows, no more.

> If I erase the index bla_idx1, then [C] select will wait, same as [B]
> select will wait.

I don't think so.  If it does, it's a bug; please provide a reproducible
test case.
        regards, tom lane


pgsql-sql by date:

Previous
From: Janning Vygen
Date:
Subject: Re: Update in all tables
Next
From: Scott Marlowe
Date:
Subject: Re: Update in all tables