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

From: Vik Fearing <vik(at)postgresfriends(dot)org>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Nico Williams <nico(at)cryptonector(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 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-19 19:01:39
Message-ID: 254d4733-29b6-4152-bd06-c292ee002790@postgresfriends.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 19/05/2025 12:25, Aleksander Alekseev wrote:
> Tom, Nico, Vik,
>
>> TABLESAMPLE is hitched to a <table primary> which can be basically
>> anything resembling a relation. So it appears the standard already
>> allows this and we just need to implement it.
> Vik, many thanks for sharing this. I don't have a strong opinion on
> `FETCH SAMPLE FIRST 10 ROWS ONLY` but since TABLESAMPLE should / may
> work for subqueries anyway we could focus on it for now.

Yeah, putting this into <fetch first clause> was a dumb idea on my part,
and Tom correctly corrected me.  I do not yet have the required number
of years in the sql standards studies to know the whole thing by heart.

I think we (as a community) should work on expanding our <sample clause>
to work with any <table primary> and not just a base table.  Especially
since we already have two existing extensions by Petr to the standard
for that clause.  We can easily make more, which might even make their
way back into the standard.

--

Vik Fearing

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2025-05-19 19:37:14 Re: strange perf regression with data checksums
Previous Message Peter Geoghegan 2025-05-19 18:44:16 Re: strange perf regression with data checksums