Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread Craig Ringer
Scott Marlowe wrote: The serial based approach sounds a fair bit better. Er, I meant "sequence". Add prepared select statements and you'd get get pretty fast performance. Yep, and if DB round trips are a problem it can always be wrapped up in a stored procedure. I'd be tempted to do

Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread Craig Ringer
Scott Marlowe wrote: Sure, but you have to trap that all the time. The solution using a cycling sequence keeps you from ever seeing that (unless you managed to check out all 9,999 other values while still getting the current one. No locking needed, dozens of updaters running concurrently and no

Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread Scott Marlowe
On Thu, Apr 3, 2008 at 12:58 PM, Craig Ringer <[EMAIL PROTECTED]> wrote: > Scott Marlowe wrote: > > > Sure, but you have to trap that all the time. The solution using a > > cycling sequence keeps you from ever seeing that (unless you managed > > to check out all 9,999 other values while still gett

Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread Craig Ringer
Scott Marlowe wrote: > On Thu, Apr 3, 2008 at 11:45 AM, Craig Ringer > <[EMAIL PROTECTED]> wrote: >> rihad wrote: >> > Given this type query: >> > >> > UPDATE bw_pool >> > SET user_id=? >> > WHERE bw_id= >> > (SELECT MIN(bw_id) FROM bw_pool WHERE user_i

Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread Scott Marlowe
On Thu, Apr 3, 2008 at 11:45 AM, Craig Ringer <[EMAIL PROTECTED]> wrote: > rihad wrote: > > Given this type query: > > > > UPDATE bw_pool > > SET user_id=? > > WHERE bw_id= > > (SELECT MIN(bw_id) FROM bw_pool WHERE user_id IS NULL) > > RETURNIN

Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread Sam Mason
On Thu, Apr 03, 2008 at 09:44:55PM +0500, rihad wrote: > Given this type query: > > UPDATE bw_pool > SET user_id=? > WHERE bw_id= > (SELECT MIN(bw_id) FROM bw_pool WHERE user_id IS NULL) > RETURNING bw_id > > The idea is to "single-threadedly" get a

Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread Scott Marlowe
On Thu, Apr 3, 2008 at 11:42 AM, Scott Marlowe <[EMAIL PROTECTED]> wrote: > On Thu, Apr 3, 2008 at 11:32 AM, rihad <[EMAIL PROTECTED]> wrote: > > Scott Marlowe wrote: > > > > > On Thu, Apr 3, 2008 at 10:44 AM, rihad <[EMAIL PROTECTED]> wrote: > > > > > > > Given this type query: > > > > > >

Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread Craig Ringer
rihad wrote: > Given this type query: > > UPDATE bw_pool > SET user_id=? > WHERE bw_id= > (SELECT MIN(bw_id) FROM bw_pool WHERE user_id IS NULL) > RETURNING bw_id Can you use a SERIALIZABLE transaction and avoid the explicit lock? If I'm not mistak

Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread Scott Marlowe
On Thu, Apr 3, 2008 at 11:32 AM, rihad <[EMAIL PROTECTED]> wrote: > Scott Marlowe wrote: > > > On Thu, Apr 3, 2008 at 10:44 AM, rihad <[EMAIL PROTECTED]> wrote: > > > > > Given this type query: > > > > > >UPDATE bw_pool > > >SET user_id=? > > >WHERE bw_id= > > >

Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread rihad
Scott Marlowe wrote: On Thu, Apr 3, 2008 at 10:44 AM, rihad <[EMAIL PROTECTED]> wrote: Given this type query: UPDATE bw_pool SET user_id=? WHERE bw_id= (SELECT MIN(bw_id) FROM bw_pool WHERE user_id IS NULL) RETURNING bw_id The idea is to "single

Re: [GENERAL] choosing the right locking mode

2008-04-03 Thread Scott Marlowe
On Thu, Apr 3, 2008 at 10:44 AM, rihad <[EMAIL PROTECTED]> wrote: > Given this type query: > > UPDATE bw_pool > SET user_id=? > WHERE bw_id= > (SELECT MIN(bw_id) FROM bw_pool WHERE user_id IS NULL) > RETURNING bw_id > > The idea is to "single-threade

[GENERAL] choosing the right locking mode

2008-04-03 Thread rihad
Given this type query: UPDATE bw_pool SET user_id=? WHERE bw_id= (SELECT MIN(bw_id) FROM bw_pool WHERE user_id IS NULL) RETURNING bw_id The idea is to "single-threadedly" get at the next available empty slot, no matter how many such queries run in