On Wed, Apr 18, 2012 at 08:38:42PM +0400, Oleg Broytman wrote:
> On Wed, Apr 18, 2012 at 12:30:10PM -0400, Adam Berg <adamb...@gmail.com> 
> wrote:
> > What is the best way to select a single random record from a table and
> > falls within the "where" criteria i have defined? I don't want to return a
> > huge result set each time and then pick a random one
> 
>    Please define "random" in the context of your task. Do you want a
> different record every time? Or some non-deterministic record that could
> be the same every time is a possible solution?

Obviously, i cannot defined «random» in his context, but I have
a somewhat related problem.

To me «random» means that every record is equally likely as
the return of the next execution of the query, where «likely»
can be entirely subjective seen from the user's point of view.

In my context the issue is a queue of number crunching jobs,
where a number of clients (10-100; maybe more) will query
for the next parameter set to run the calculation for.
A client receiving a job will set a field to indicate that
it is taken, and transaction locking is used to avoid 
multiple clients snitching the same job at the same time.

Ideally, I would have liked a query to retrieve the first
unlocked record (it is useful but not necessary to order
them by timestamp).

Random selection, which makes it unlikely that a client will
have to wait for the lock would be a useful second best. 

Or maybe there is another ingenious approach which I have not
thought of.  Admittedly, this is a quick and dirty solution
which seems to work.

-- 
:-- Hans Georg

------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to