Re: plan problem

Поиск
Список
Период
Сортировка
От Richard Huxton
Тема Re: plan problem
Дата
Msg-id 200404070938.11482.dev@archonet.com
обсуждение исходный текст
Ответ на plan problem  (Ken Geis <kgeis@speakeasy.org>)
Ответы Re: plan problem  (Ken Geis <kgeis@speakeasy.org>)
Список pgsql-performance
On Tuesday 06 April 2004 21:25, Ken Geis wrote:
> I am trying to find an efficient way to draw a random sample from a
> complex query.  I also want it to be easy to use within my application.
>
> So I've defined a view that encapsulates the query.  The id in the
> "driving" table is exposed, and I run a query like:
>
> select * from stats_record_view
>   where id in (select id from driver_stats
>                 order by random()
>                 limit 30000);

How about a join?

SELECT s.*
FROM
stats_record_view s
JOIN
(SELECT id FROM driver_stats ORDER BY random() LIMIT 30000) AS r
ON s.id = r.id;

Or, what about a cursor and fetch forward (or back?) a random number of rows
before each fetch. That's probably not going to be so random though.

Also worth checking the various list archives - this has come up in the past,
but some time ago.

--
  Richard Huxton
  Archonet Ltd

В списке pgsql-performance по дате отправления:

Предыдущее
От: Richard Huxton
Дата:
Сообщение: Re: good pc but bad performance,why?
Следующее
От: huang yaqin
Дата:
Сообщение: Re: good pc but bad performance,why?