Subject Re: [firebird-php] ORDER By RAND() executes very slow
Author Lester Caine
bdwankhede wrote:
> Hello all,
>
> I have a simple firebird sql query as
>
> SELECT FIRST 1000 a."id", a."what_they_do", a."does", a."improves"
> FROM "inspections" a ORDER BY RAND() ASC;
>
> where "inspections" table having large no of records and containing text fields but by using ORDER BY RAND() it executes very slow
>
> please help ... how can i improve this query to get random records?

I doubt that one can, since 1000 random records is probably reading the whole
table into memory and then trying to find a 'random' assortment of those records
... ASC is not appropriate, since you are not specifying anything to 'ascend',
but why do you need so many random records. They can't easily be displayed.
Normally one would just be pulling 10 or so random records for a random display.

--
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk//
Firebird - http://www.firebirdsql.org/index.php