Subject | Re: ORDER By RAND() executes very slow |
---|---|
Author | bdwankhede |
Post date | 2010-05-04T06:50:58Z |
Many thanks for response.
I have to run a CLI php script on 1000 random rows which search for any specific words in the table fields and i have to replace these words with another one and we have to run this script weekly or monthly as new records stored into the table having large no of records
I have to run a CLI php script on 1000 random rows which search for any specific words in the table fields and i have to replace these words with another one and we have to run this script weekly or monthly as new records stored into the table having large no of records
--- In firebird-php@yahoogroups.com, Lester Caine <lester@...> wrote:
>
> 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
>