Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-02-04 Thread Bruce Momjian
Jeff Davis wrote: > On Wed, 2009-02-04 at 11:11 -0500, Bruce Momjian wrote: > > Well, with no one replying, :-(, I went ahead and added to the Read > > Committed section of our manual to show a simple case where our read > > committed mode produces undesirable results. I also did a little > > clea

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-02-04 Thread Jeff Davis
On Wed, 2009-02-04 at 11:11 -0500, Bruce Momjian wrote: > Well, with no one replying, :-(, I went ahead and added to the Read > Committed section of our manual to show a simple case where our read > committed mode produces undesirable results. I also did a little > cleanup at the same time. We co

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-02-04 Thread Bruce Momjian
Kevin Grittner wrote: > >>> Bruce Momjian wrote: > > Well, with no one replying, :-(, I went ahead and added to the Read > > Committed section of our manual to show a simple case where our read > > committed mode produces undesirable results. I also did a little > > cleanup at the same time. > >

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-02-04 Thread Kevin Grittner
>>> Bruce Momjian wrote: > Well, with no one replying, :-(, I went ahead and added to the Read > Committed section of our manual to show a simple case where our read > committed mode produces undesirable results. I also did a little > cleanup at the same time. > > You can see the resulting text

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-02-04 Thread Bruce Momjian
Bruce Momjian wrote: > The fundamental behavior above is that the S1 transaction is adding > _and_ removing rows from the S2 query's result set; S2 is seeing the > pre-query values that don't match its criteria and ignoring them and > blocking on a later row that does match its criteria. Once S1

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-02-02 Thread Bruce Momjian
Bruce Momjian wrote: > The fundamental behavior above is that the S1 transaction is adding > _and_ removing rows from the S2 query's result set; S2 is seeing the > pre-query values that don't match its criteria and ignoring them and > blocking on a later row that does match its criteria. Once S1

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-02-02 Thread Bruce Momjian
Kevin Grittner wrote: > >>> Tom Lane wrote: > > Jeff Davis writes: > >> There you see a snapshot of the table that never existed. Either > the > >> snapshot was taken before the UPDATE, in which case i=3 should be > >> included, or it was taken after the UPDATE, in which case i=4 should > be > >

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-27 Thread Kevin Grittner
>>> Gregory Stark wrote: > Hopefully it's not patent encumbered? Might be better not to check > actually. I've been in correspondence with the authors. That is the first question I asked them. The response (from Michael Cahill): - There are no patent applications covering our work, as far a

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-27 Thread Gregory Stark
"Kevin Grittner" writes: >> I think Greg has it right: without predicate locking we can't really >> achieve the behavior you're expecting. So how would we better approach the >> semantics you want without it? > > Well, this thread was talking about dealing with situations where > queries using

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-27 Thread Kevin Grittner
>>> Jeff Davis wrote: > On Mon, 2009-01-26 at 15:46 -0600, Kevin Grittner wrote: >> After the COMMIT succeeds, the locks from Session1 are released. >> Session2 acquires its update lock and reads row 2, finds that it >> doesn't match its update criteria, downgrades the lock to shared, >> acquire

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Jeff Davis
On Mon, 2009-01-26 at 15:46 -0600, Kevin Grittner wrote: > After the COMMIT succeeds, the locks from Session1 are released. > Session2 acquires its update lock and reads row 2, finds that it > doesn't match its update criteria, downgrades the lock to shared, > acquires an update lock on row 3, fin

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Hannu Krosing
On Mon, 2009-01-26 at 09:26 -0800, Jeff Davis wrote: > On Mon, 2009-01-26 at 10:48 -0600, Kevin Grittner wrote: > > I guess the issue of whether this violation of ACID properties should > > be considered a bug or a feature is a separate discussion, but calling > > it a feature seems like a hard sel

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Kevin Grittner
>>> Gregory Stark wrote: > This example is a case of the same issue we were discussing earlier > involving "predicate locking". To solve it you need a way to lock > records that your query *isn't* accessing and may not even exist yet > to prevent them from being turned into (or inserted as) reco

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Gregory Stark
Jeff Davis writes: > It seems like it would be a challenge to know that the tuple with i=3 > would be updated to a value that matches the search condition j=10. So > can you tell me a little more about the mechanism by which Sybase solves > this problem? This example is a case of the same issue

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Kevin Grittner
>>> Jeff Davis wrote: > On Mon, 2009-01-26 at 14:31 -0600, Kevin Grittner wrote: >> > Do you re-run the query to find new tuples that might now satisfy >> > the search condition that didn't before? >> >> There can't be any. Blocks taken during the reading of rows so far >> have not been releas

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Jeff Davis
On Mon, 2009-01-26 at 14:31 -0600, Kevin Grittner wrote: > > Do you re-run the query to find new tuples that might now satisfy > > the search condition that didn't before? > > There can't be any. Blocks taken during the reading of rows so far > have not been released, and would preclude the upda

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Kevin Grittner
>>> Jeff Davis wrote: > The tricky part is when an UPDATE with a search condition reads, > modifies, and writes a value that is used in a search condition for > another UPDATE. > > Every DBMS will block waiting for the first UPDATE to finish. Then > what? Either it's totally safe to proceed, o

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Jeff Davis
On Mon, 2009-01-26 at 13:50 -0600, Kevin Grittner wrote: > A somewhat dated description for Sybase (it predates their support of > row level locks and the related predicate locks on indexes) is here: > > http://manuals.sybase.com/onlinebooks/group-asarc/srv10024/sag/@Generic__BookTextView/41766;p

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Kevin Grittner
>>> I wrote: > Simplified, in a READ COMMITTED transaction a SELECT takes a lock > which conflicts with update before reading, and holds it until the > executing statement is done with that table; That should have said "until after the executing statement completes." Apologies, but but I just

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Kevin Grittner
>>> Jeff Davis wrote: > I don't think this is PostgreSQL-specific, I think non-MVCC database > systems face this same choice (although the terminology would be > different). A somewhat dated description for Sybase (it predates their support of row level locks and the related predicate locks on

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Jeff Davis
On Mon, 2009-01-26 at 11:34 -0600, Kevin Grittner wrote: > READ COMMITTED is not supposed to be able to view the work of a > concurrent transactions as PARTLY applied and PARTLY committed, which > is what's happening here. If one statement in a READ COMMITTED > transaction sees the uncommitted vie

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Grzegorz Jaskiewicz
On 2009-01-26, at 17:34, Kevin Grittner wrote: . It may not surprise someone who is intimately familiar with PostgreSQL internals for a single SELECT statement to see PART of a transactions work, but it would surprise most users, and is certainly not compliant with the standard. +1000 -- Sen

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Kevin Grittner
>>> Jeff Davis wrote: > In fact, it's probably most similar to UPDATE ... RETURNING, which will > give the same result (that breaks atomicity or isolation, depending on > your point of view), which is correct for READ COMMITTED isolation > level. READ COMMITTED is not supposed to be able to vie

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Jeff Davis
On Mon, 2009-01-26 at 10:48 -0600, Kevin Grittner wrote: > I guess the issue of whether this violation of ACID properties should > be considered a bug or a feature is a separate discussion, but calling > it a feature seems like a hard sell to me. > I think I understand the other perspective on t

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-26 Thread Kevin Grittner
>>> Tom Lane wrote: > Jeff Davis writes: >> There you see a snapshot of the table that never existed. Either the >> snapshot was taken before the UPDATE, in which case i=3 should be >> included, or it was taken after the UPDATE, in which case i=4 should be >> included. So atomicity is broken for

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-24 Thread Gregory Stark
Jeff Davis writes: > On Sat, 2009-01-24 at 19:45 +, Greg Stark wrote: >> There already is quite an extensive discussion of how FOR UPDATE >> behaves including these kinds of violations. > > Not in the documentation, that I can see. And I think it's important > that it be there for the reaso

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-24 Thread Tom Lane
Jeff Davis writes: > There you see a snapshot of the table that never existed. Either the > snapshot was taken before the UPDATE, in which case i=3 should be > included, or it was taken after the UPDATE, in which case i=4 should be > included. So atomicity is broken for WHERE. This assertion is b

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-24 Thread Jeff Davis
On Sat, 2009-01-24 at 19:45 +, Greg Stark wrote: > There already is quite an extensive discussion of how FOR UPDATE > behaves including these kinds of violations. Not in the documentation, that I can see. And I think it's important that it be there for the reasons I mentioned. Can you refer

Re: [HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-24 Thread Greg Stark
There already is quite an extensive discussion of how FOR UPDATE behaves including these kinds of violations. What you propose is interesting though. It would have been impossible before subtransactions but it's doable now. Still the performance might be unusable for complex queries. It's b

[HACKERS] More FOR UPDATE/FOR SHARE problems

2009-01-24 Thread Jeff Davis
This post is a follow-up of an off-list discussion with Nathan Boley. All references to FOR UPDATE apply to FOR SHARE as well. create table a(i int, j int); insert into a values(1, 10); insert into a values(2, 10); insert into a values(3, 10); insert into a values(4, 20); insert into a values(5, 2