On Wed, 2 Jul 2003 19:32:13 +0400 Монашёв Михаил
<[EMAIL PROTECTED]> wrote:

> I have big table (50 000 records, 100 Mb), and want to get 1 random
> record from it.
> 
> CREATE TABLE news (
>   id int(10) unsigned NOT NULL auto_increment,
>   description varchar(255) NOT NULL default '',
>   PRIMARY KEY  (id)
> ) TYPE=MyISAM PACK_KEYS=1 CHECKSUM=1 DELAY_KEY_WRITE=1;
> 
> 
> $max_id='SELECT MAX(id) FROM news';
> $id = int(rand()*$max_id+1);
> 'SELECT description WHERE ID='.$id;
> 
> it's vary slow way. May be somebody have better idia?
> I use MySQL 3.23

The devil is probably in the details.  What is the exact code you are
using to extract the values?  Is this a one request per program run or
are you doing this several times per program run?

50K isn't all that big.  If you are fetching randomly more than once,
just slurping the descriptions into an array and then selecting from
that may work better.  You may want to sort by ID to make it
repeatable, but that isn't essential if you are selecting randomly
anyway.

-- 
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.catb.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.

  • ... Rudy Lippan
    • ... Монашёв Михаил
      • ... Michael A Chase
        • ... Монашёв Михаил
      • ... Thomas A. Lowery
        • ... Монашёв Михаил
        • ... Ronald J Kimball

Reply via email to