Re: FETCH FIRST clause PERCENT option

From: Jaime Casanova <jcasanov(at)systemguards(dot)com(dot)ec>
To: Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>
Cc: surafel3000(at)gmail(dot)com, michael(at)paquier(dot)xyz, vik(dot)fearing(at)2ndquadrant(dot)com, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, ryan(at)rustprooflabs(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: FETCH FIRST clause PERCENT option
Date: 2021-01-26 09:19:19
Message-ID: CAJKUy5ge=Mgqd6QmLs+Zm1e5O17yvw1QqbWQc4BZECir2=6XRA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jan 25, 2021 at 6:39 AM Kyotaro Horiguchi
<horikyota(dot)ntt(at)gmail(dot)com> wrote:
>
> Sorry for the dealy. I started to look this.
>
> At Fri, 25 Sep 2020 12:25:24 +0300, Surafel Temesgen <surafel3000(at)gmail(dot)com> wrote in
> > Hi Michael
> > On Thu, Sep 24, 2020 at 6:58 AM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
> >
> > > On Mon, Aug 10, 2020 at 01:23:44PM +0300, Surafel Temesgen wrote:
> > > > I also Implement PERCENT WITH TIES option. patch is attached
> > > > i don't start a new tread because the patches share common code
> > >
> > > This fails to apply per the CF bot. Could you send a rebase?
>
> This still applies on the master HEAD.
>
> percent-incremental-v11.patch
>
> The existing nodeLimit passes the slot of the subnode to the
> caller. but this patch changes that behavior. You added a new function
> to tuplestore.c not to store a minimal tuple into the slot that passed
> from subnode, but we should refrain from scribbling on the slot passed
> from the subnode. Instead, the PERCENT path of the limit node should
> use its own ResultTupleSlot for the purpose. See nodeSort for a
> concrete example.
>
>
> + LIMIT_OPTION_PER_WITH_TIES, /* FETCH FIRST... PERCENT WITH TIES */
>
> That name is a bit hard to read. We should spell it with complete
> words.
>
> case LIMIT_INWINDOW:
> ...
> + if (IsPercentOption(node->limitOption) && node->backwardPosition
> ...
> + if (IsPercentOption(node->limitOption) && node->reachEnd)
> ...
> + if (IsPercentOption(node->limitOption))
>
> I think we can use separate lstate state for each condition above
> since IsPercentOption() gives a constant result through the execution
> time. For example, LIMIT_PERCENT_TUPLESLOT_NOT_FILLED and
> LIMIT_PERCENT_TUPLESLOT_FILLED and some derived states similar to the
> non-percent path. I *feel* that makes code simpler.
>
> What do you think about this?
>
> regards.
>
> --
> Kyotaro Horiguchi
> NTT Open Source Software Center
>
>

Hi,

I was testing this and found that it doesn't work well with
subselects, this query make the server crash:

"""
select * from pg_type where exists (select 1 from pg_authid fetch
first 10 percent rows only);
"""

postgres was compiled with these options:

"""
CFLAGS="-ggdb -O0 -g3 -fno-omit-frame-pointer" ./configure
--prefix=/opt/var/pgdg/14dev/percent --enable-debug --enable-cassert
--with-pgport=54314 --enable-depend
"""

attached is the stack trace

--
Jaime Casanova
Director de Servicios Profesionales
SystemGuards - Consultores de PostgreSQL

Attachment Content-Type Size
gdb_fetch_percent.txt text/plain 7.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Drouvot, Bertrand 2021-01-26 09:31:33 Re: [UNVERIFIED SENDER] Re: Minimal logical decoding on standbys
Previous Message Hamid Akhtar 2021-01-26 09:07:09 Re: Bug in error reporting for multi-line JSON