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
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
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
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
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
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
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
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
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
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
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
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
12 matches
Mail list logo