Re: Efficiently finding a random record

2005-05-16 Thread Philip Hallstrom
Michael Stassen wrote: For example, if the selected random id is missing, we take the next id we find, like this: SELECT @rand_id:= CAST( 1 + MAX(id)*RAND() AS UNSIGNED) FROM history; SELECT * FROM history WHERE id >= @rand_id LIMIT 1; That will have a possibly undesired effect. Records that

Re: Efficiently finding a random record

2005-05-16 Thread Keith Ivey
Michael Stassen wrote: For example, if the selected random id is missing, we take the next id we find, like this: SELECT @rand_id:= CAST( 1 + MAX(id)*RAND() AS UNSIGNED) FROM history; SELECT * FROM history WHERE id >= @rand_id LIMIT 1; That will have a possibly undesired effect. Records that

Re: Efficiently finding a random record

2005-05-15 Thread Michael Stassen
Eric Bergen wrote: in() can take millions of arguments. Up to max packet size. Try it :) True, but several past threads have suggested that performance drops dramatically when the size of the IN list gets too large. As IN is equivalent to an equality check for each value in the list, separated b

Re: Efficiently finding a random record

2005-05-15 Thread Michael Stassen
riginal Message - From: <[EMAIL PROTECTED]> To: "Gary Huntress" <[EMAIL PROTECTED]> Cc: Sent: Sunday, May 15, 2005 6:42 AM Subject: Re: Efficiently finding a random record Hi, i did the test and agree with you. even with Select ID from history where id = 1+CAST( rand

Re: Efficiently finding a random record

2005-05-15 Thread Gary Huntress
tress" <[EMAIL PROTECTED]> Cc: Sent: Sunday, May 15, 2005 6:42 AM Subject: Re: Efficiently finding a random record Hi, i did the test and agree with you. even with Select ID from history where id = 1+CAST( rand() * 19 as UNSIGNED) limit 1; when testing : select CAST( rand() * 1

Re: Efficiently finding a random record

2005-05-15 Thread mfatene
en" <[EMAIL PROTECTED]> > To: "Dan Bolser" <[EMAIL PROTECTED]> > Cc: "Philip Hallstrom" <[EMAIL PROTECTED]>; "Brian Dunning" > <[EMAIL PROTECTED]>; > Sent: Friday, May 13, 2005 7:48 PM > Subject: Re: Efficiently findi

Re: Efficiently finding a random record

2005-05-14 Thread Gary Huntress
rom: "Eric Bergen" <[EMAIL PROTECTED]> To: "Dan Bolser" <[EMAIL PROTECTED]> Cc: "Philip Hallstrom" <[EMAIL PROTECTED]>; "Brian Dunning" <[EMAIL PROTECTED]>; Sent: Friday, May 13, 2005 7:48 PM Subject: Re: Efficiently finding a random r

Re: Efficiently finding a random record

2005-05-13 Thread Eric Bergen
in() can take millions of arguments. Up to max packet size. Try it :) Dan Bolser wrote: On Fri, 13 May 2005, Eric Bergen wrote: Even better is if you have an integer primary key (think auto_increment) and use in() So if you want 10 random rows in your app generate 20 or so random numbers and

Re: Efficiently finding a random record

2005-05-13 Thread Dan Bolser
On Fri, 13 May 2005, Eric Bergen wrote: >Even better is if you have an integer primary key (think auto_increment) >and use in() > >So if you want 10 random rows in your app generate 20 or so random >numbers and do something like >select col1, from t where x in (1, 5, 3, 2...) limit 10 > >check n

Re: Efficiently finding a random record

2005-05-13 Thread Eric Bergen
Even better is if you have an integer primary key (think auto_increment) and use in() So if you want 10 random rows in your app generate 20 or so random numbers and do something like select col1, from t where x in (1, 5, 3, 2...) limit 10 check num rows and if you don't get enough generate more

Re: Efficiently finding a random record

2005-05-13 Thread Philip Hallstrom
I have a db of about 300,000 records and when I try to find one random record like this: select * from table order by rand() limit 1; it can take several minutes. My Sherlock Holmes instincts tell me that what I'm doing is somehow inefficient. What is the primary culprit here? The culprit is tha

Re: Efficiently finding a random record

2005-05-13 Thread Frank Bax
At 12:54 PM 5/13/05, Brian Dunning wrote: I have a db of about 300,000 records and when I try to find one random record like this: select * from table order by rand() limit 1; it can take several minutes. My Sherlock Holmes instincts tell me that what I'm doing is somehow inefficient. What is the p