SitePoint Sponsor

User Tag List

Results 1 to 23 of 23

Threaded View

  1. #1
    SitePoint Addict bimalpoudel's Avatar
    Join Date
    Feb 2009
    Location
    Kathmandu, Nepal
    Posts
    279
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Speedy: ORDER BY RAND() operation

    What can be done to make the following query run faster?
    file_id is the primary key on the table (index)
    Code:
    # Random playlist
    SELECT
    	file_name `title`,
    	REPLACE(file_path, 'P:/', '') `location`
    FROM physical_files
    ORDER BY
    	RAND()
    LIMIT 30;
    I have several records in the database. And, this query is just not efficient. I want to draw random files, but ORDER BY is not good here.

    There is an interesting post on similar topic on Anton Titov. Stil my problem cannot be solved. I cannot generate the list of random file_ids randomly in PHP, because, they may not exist or, filtered within WHERE condition.

    Thank you in advance for a good suggestion.
    Last edited by bimalpoudel; Jan 21, 2011 at 14:33. Reason: remove url added
    Bimal Poudel @ Sanjaal Framework » over Smarty Template Engine
    ASKING INTERESTING QUESTIONS ON SITEPOINT FOURM

    Hire for coding support - PHP/MySQL


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •