Re: FETCH FIRST clause PERCENT option - Mailing list pgsql-hackers

From Andres Freund
Subject Re: FETCH FIRST clause PERCENT option
Date
Msg-id 20180816143421.rxla4tonz2dx5xez@alap3.anarazel.de
Whole thread Raw
In response to FETCH FIRST clause PERCENT option  (Surafel Temesgen <surafel3000@gmail.com>)
Responses Re: FETCH FIRST clause PERCENT option
Re: FETCH FIRST clause PERCENT option
Re: FETCH FIRST clause PERCENT option
List pgsql-hackers
Hi,

On 2018-08-16 17:27:45 +0300, Surafel Temesgen wrote:
> FETCH FIRST with PERCENT option is SQL standard that state limit count to
> be specified in a percentage in addition to specify it in exact count and
> listed as one of Major features simply not implemented yet in recent wiki
> page [1].
> 
> I implemented it by executing the query plan twice. One without limit
> filter to find the total number of row that will be feed to limit node so
> the exact limit count can be calculated and the query plan execute again
> with limit filter with newly calculated exact count .

Won't that have rather massive issues with multiple evaluations of
clauses in the query?  Besides being really expensive?

I think you'd have to instead spill the query results into a tuplestore
(like we do for FOR HOLD queries at end of xact), and then do the
computations based on that.

- Andres


pgsql-hackers by date:

Previous
From: Surafel Temesgen
Date:
Subject: FETCH FIRST clause PERCENT option
Next
From: Andrew Gierth
Date:
Subject: Re: FETCH FIRST clause PERCENT option