You are here: Re: [PHP] How to find random records in a subset? « PHP « IT news, forums, messages
Re: [PHP] How to find random records in a subset?

Posted by Jochem Maas on 06/05/05 23:40

Brian Dunning wrote:
> I am using a routine to find 50 random records in a large MySQL

how random does it need to be? if *psuedo* (nobody start on the
computer random is not really random argument - go watch "What the bleep
do we know?" instead) random is okay maybe you could define a list
of [funky/weird] ORDER BY subclauses and randomly
pick one to add to you sql query. by funky/weird I meaning using
multiple comlumn and direction indentifiers in unusual combinations.

to increase the psuedo randomness you could potentially use a randomized
FIRST declaration (or OFFSET in MySQL) - rather like you would with a
pagination routine. but thats dependent on the size of the constrained
resultset you get.

or alternatively, copy the data offline. run a "nice -19'd" script to
generate a batch of random 50 item sets. then let the online site
use the generated sets ... item [ids] in a set not found in the live DB could
be filled in by a query using the same where clause (but without the randomization)
and with a relevant FIRST, SKIP declaration for the 'fill', which
assuming your tables are indexed properly should be fast.

hope thats understandable.
rgds,
Jochem

> database (about a million records) where I generate a list of 50 random
> unique ID's, and then use MySQL's "in" command to find them. I can't
> use "order by rand()" due to its performance hit.
>
> But I have to take it one more step: I want to first limit my found set
> to those matching a different search criteria, and then find 50 of those.
>
> Anyone? Can this be done all within MySQL, or is it going to require
> some humongo PHP arrays?
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация