List:General Discussion« Previous MessageNext Message »
From:Michael Widenius Date:November 14 1999 8:53pm
Subject:Re: Limiting mysql threads
View as plain text  
>>>>> "Robert" == Robert A Crawford <crawford@stripped> writes:

Robert> On Thu, Nov 04, 1999 at 06:01:42PM +0000, Graham Ashton wrote:
>> I have two columns (actually I have more, but they're not relevant here) in
>> my table. 
>> - `id' is simply an integer that relates directly to a real life event
>> (that I'm monitoring).

Robert> What assigns the id to an event? If you create it yourself,
Robert> use an autoincrement column. If the id is externally assigned:

Robert> 1. Attempt the update.
Robert> 2. If no rows were updated,
Robert> 2.1 Try to get an advisory lock (with GET_LOCK()) for
Robert> that id.
Robert> 2.2 If you get the lock, insert the row, release the lock,
Robert> and continue.
Robert> 2.3 If the lock is already held, start over with 1.

Robert> This way, you never really lock the table, just issue an advisory
Robert> that someone's creating that ID.

Hi!

Why not instead do it this way:


1. Attempt the update.
2. If no rows were updated,
2.1 Insert the row.
2.2 If the insert failed because of a dupplicate key, another thread
    did create the row in the mean time.
2.3.1 Update the row that you now know exist.

Regards,
Monty
Thread
Limiting mysql threadsRen Haddock26 Oct
  • Re: Limiting mysql threadsVivek Khera26 Oct
  • Re: Limiting mysql threadsDan Nelson26 Oct
    • Re: Limiting mysql threadsGraham Ashton4 Nov
      • Re: Limiting mysql threadsMatthias Urlichs4 Nov
      • Re: Limiting mysql threadssinisa4 Nov
        • Re: Limiting mysql threadsGraham Ashton4 Nov
          • Re: Limiting mysql threadssinisa4 Nov
            • Re: Limiting mysql threadsGraham Ashton4 Nov
              • Re: Limiting mysql threadsRobert A. Crawford4 Nov
                • Re: Limiting mysql threadsMichael Widenius15 Nov