Re: Should we optimize the `ORDER BY random() LIMIT x` case?

From: Nico Williams <nico(at)cryptonector(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Aleksander Alekseev <aleksander(at)timescale(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andrei Lepikhov <lepihov(at)gmail(dot)com>, wenhui qiu <qiuwenhuifx(at)gmail(dot)com>
Subject: Re: Should we optimize the `ORDER BY random() LIMIT x` case?
Date: 2025-05-16 21:50:49
Message-ID: aCezOeKRnvVUHml1@ubby
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nico Williams 2025-05-16 21:53:29 Re: Should we optimize the `ORDER BY random() LIMIT x` case?
Previous Message Vik Fearing 2025-05-16 21:42:59 Re: Should we optimize the `ORDER BY random() LIMIT x` case?