You're right, you may be penalised with having to wait. But there are advantages in this.

Firstly, is or is not a requirement that two SELECTs are prevented from occuring at the same time?

Thus can you or can you not afford to risk having two processes perform that SELECT at the same time?

You have a choice. Risk it. Or use a lock of some sort to protect against the situation whereby both processes have nothing else to do but perform a SELECT.

Think about it. Reading a record from a database (SELECT) is likely to take a fraction of the time that writing a record to the database will take (DELETE). Hence, the odds of both your processes attempting to SELECT at the same time are low.

So this approach will give you SAFETY while using multiple processes. You could scale to 3, 4, or 10 processes using this technique.

Other techniques all impose overhead as well (and odd/even approaches perform worse if the processing time between processes varies at all).

Update: changed grammar a little.

Update 2: as pointed out by the reply to this post by Foxcub I was wrong to ignore the fact that the DELETE also needs to occur within the atomic action that contains the SELECT. Apologies.

Update 3: added readmore tags.


In reply to Re^3: Database queue logic by monarch
in thread Database queue logic by Marcello

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.