Re: Should we optimize the `ORDER BY random() LIMIT x` case? - Mailing list pgsql-hackers

From Nico Williams
Subject Re: Should we optimize the `ORDER BY random() LIMIT x` case?
Date
Msg-id aCezOeKRnvVUHml1@ubby
Whole thread Raw
In response to Re: Should we optimize the `ORDER BY random() LIMIT x` case?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Fri, May 16, 2025 at 09:01:50AM -0400, Tom Lane wrote:
> Seems to me the obvious answer is to extend TABLESAMPLE (or at least, some
> of the tablesample methods) to allow it to work on a subquery.

The key here is that we need one bit of state between rows: the count of
rows seen so far.



pgsql-hackers by date:

Previous
From: Vik Fearing
Date:
Subject: Re: Should we optimize the `ORDER BY random() LIMIT x` case?
Next
From: Nico Williams
Date:
Subject: Re: Should we optimize the `ORDER BY random() LIMIT x` case?