On Mon, Jan 25, 2021 at 6:39 AM Kyotaro Horiguchi
<horikyota....@gmail.com> wrote:
>
> Sorry for the dealy. I started to look this.
>
> At Fri, 25 Sep 2020 12:25:24 +0300, Surafel Temesgen <surafel3...@gmail.com> 
> wrote in
> > Hi Michael
> > On Thu, Sep 24, 2020 at 6:58 AM Michael Paquier <mich...@paquier.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
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
        set = {__val = {0, 140724437079104, 2, 6, 6458975, 94647092334544, 
4611686018427388799, 139701007526566, 0, 281470681751456, 0, 0, 0, 0, 0, 0}}
        pid = <optimized out>
        tid = <optimized out>
        ret = <optimized out>
#1  0x00007f0eacb55535 in __GI_abort () at abort.c:79
        save_stage = 1
        act = {__sigaction_handler = {sa_handler = 0x0, sa_sigaction = 0x0}, 
sa_mask = {__val = {0, 0, 0, 0, 0, 139701005283317, 2, 3760846768312216920, 
7018409443653412194, 94647092334544, 
              7003717752975484000, 0, 3976935554753230848, 140724437079344, 0, 
140724437080208}}, sa_flags = -1101967408, sa_restorer = 0x0}
        sigs = {__val = {32, 0 <repeats 15 times>}}
#2  0x00005614beb8d44e in ExceptionalCondition (conditionName=0x5614bed22e7b 
"limit->consttype == INT8OID", errorType=0x5614bed22b76 "FailedAssertion", 
fileName=0x5614bed22c44 "subselect.c", lineNumber=1594)
    at assert.c:69
No locals.
#3  0x00005614be8df87d in simplify_EXISTS_query (root=0x5614bfecf4b8, 
query=0x5614bfe038e0) at subselect.c:1594
        node = 0x5614bfed0190
        limit = 0x5614bfed0190
#4  0x00005614be8df49b in convert_EXISTS_sublink_to_join (root=0x5614bfecf4b8, 
sublink=0x5614bfe036e0, under_not=false, available_rels=0x5614bfecf1d8) at 
subselect.c:1420
        result = 0x5614bfecf940
        parse = 0x5614bfe039f8
        subselect = 0x5614bfe038e0
        whereClause = 0x5614bfecf8b8
        rtoffset = 22036
        varno = 22036
        clause_varnos = 0x18
        upper_varnos = 0x20
#5  0x00005614be8e3d8d in pull_up_sublinks_qual_recurse (root=0x5614bfecf4b8, 
node=0x5614bfe036e0, jtlink1=0x7ffcf6155a48, available_rels1=0x5614bfecf1d8, 
jtlink2=0x0, available_rels2=0x0) at prepjointree.c:458
        sublink = 0x5614bfe036e0
        j = 0x0
        child_rels = 0x5614bfecf940
#6  0x00005614be8e38cc in pull_up_sublinks_jointree_recurse 
(root=0x5614bfecf4b8, jtnode=0x5614bfecf3d0, relids=0x7ffcf6155ab0) at 
prepjointree.c:275
        frelids = 0x5614bfecf1d8
        newf = 0x5614bfecf928
        jtlink = 0x5614bfecf928
        f = 0x5614bfecf3d0
        newfromlist = 0x5614bfecf8d0
        l = 0x0
        __func__ = "pull_up_sublinks_jointree_recurse"
#7  0x00005614be8e36ce in pull_up_sublinks (root=0x5614bfecf4b8) at 
prepjointree.c:214
        jtnode = 0x5614bfecf6e8
        relids = 0x0
#8  0x00005614be8c9e6a in subquery_planner (glob=0x5614bfe2acc0, 
parse=0x5614bfe039f8, parent_root=0x0, hasRecursion=false, tuple_fraction=0) at 
planner.c:657
        root = 0x5614bfecf4b8
        newWithCheckOptions = 0x5614bfe039f8
        newHaving = 0x7ffcf6155c10
        hasOuterJoins = false
        hasResultRTEs = false
        final_rel = 0x0
        l = 0x7ffcf6155c10
#9  0x00005614be8c9320 in standard_planner (parse=0x5614bfe039f8, 
query_string=0x5614bfe02710 "select * from pg_type where exists (select 1 from 
pg_authid fetch first 10 percent rows only);", 
    cursorOptions=256, boundParams=0x0) at planner.c:402
        result = 0x5614bebc847f <palloc+273>
        glob = 0x5614bfe2acc0
        tuple_fraction = 0
        root = 0x5614be859263 <lappend+141>
        final_rel = 0x7ffcf6155cf0
        best_path = 0x5614bfecf460
        top_plan = 0x7ffcf6155d80
        lp = 0x7f0ea3a06970
        lr = 0x5614be858d7a <new_list+103>
#10 0x00005614be8c90d7 in planner (parse=0x5614bfe039f8, 
query_string=0x5614bfe02710 "select * from pg_type where exists (select 1 from 
pg_authid fetch first 10 percent rows only);", cursorOptions=256, 
    boundParams=0x0) at planner.c:273
        result = 0x5614bfe039f8
#11 0x00005614be9fab27 in pg_plan_query (querytree=0x5614bfe039f8, 
query_string=0x5614bfe02710 "select * from pg_type where exists (select 1 from 
pg_authid fetch first 10 percent rows only);", 
    cursorOptions=256, boundParams=0x0) at postgres.c:876
        plan = 0xe5be9faa58
#12 0x00005614be9fac5d in pg_plan_queries (querytrees=0x5614bfecf460, 
query_string=0x5614bfe02710 "select * from pg_type where exists (select 1 from 
pg_authid fetch first 10 percent rows only);", 
    cursorOptions=256, boundParams=0x0) at postgres.c:967
        query = 0x5614bfe039f8
        stmt = 0x5614bfe03850
        query_list__state = {l = 0x5614bfecf460, i = 0}
        stmt_list = 0x0
        query_list = 0x5614bfecf478
#13 0x00005614be9fafc0 in exec_simple_query (query_string=0x5614bfe02710 
"select * from pg_type where exists (select 1 from pg_authid fetch first 10 
percent rows only);") at postgres.c:1159
        snapshot_set = true
        per_parsetree_context = 0x0
        plantree_list = 0x5614be514fd0 <_start>
        parsetree = 0x5614bfe03850
        commandTag = CMDTAG_SELECT
        qc = {commandTag = CMDTAG_UNKNOWN, nprocessed = 403726925833}
        querytree_list = 0x5614bfecf460
        portal = 0x0
        receiver = 0x5614beba5eb2 <pg_any_to_server+88>
        format = 0
        parsetree_item__state = {l = 0x5614bfe03888, i = 0}
        dest = DestRemote
        oldcontext = 0x5614bfeab730
        parsetree_list = 0x5614bfe03888
        parsetree_item = 0x5614bfe038a0
        save_log_statement_stats = false
        was_logged = false
        use_implicit_block = false
        msec_str = 
"L\000\000\000\002\000\000\000d\000\000\000\000\000\000\000\020'\340\277\024V\000\000^\000\000\000\006\000\000"
        __func__ = "exec_simple_query"
#14 0x00005614be9ff65a in PostgresMain (argc=1, argv=0x7ffcf61560c0, 
dbname=0x5614bfe2e620 "regression", username=0x5614bfe2e5f8 "jcasanov") at 
postgres.c:4394
        query_string = 0x5614bfe02710 "select * from pg_type where exists 
(select 1 from pg_authid fetch first 10 percent rows only);"
        firstchar = 81
        input_message = {data = 0x5614bfe02710 "select * from pg_type where 
exists (select 1 from pg_authid fetch first 10 percent rows only);", len = 95, 
maxlen = 1024, cursor = 95}
        local_sigjmp_buf = {{__jmpbuf = {0, 3987624110899253739, 
94647092334544, 140724437083232, 0, 0, 3987624109703877099, 
7243602486371340779}, __mask_was_saved = 1, __saved_mask = {__val = {0, 0, 0, 
0, 0, 
                0, 0, 33022, 14935519656805164164, 0, 1099511627520, 0, 0, 
4294901760, 18446462598732840960, 0}}}}
        send_ready_for_query = false
        idle_in_transaction_timeout_enabled = false
        idle_session_timeout_enabled = false
        __func__ = "PostgresMain"
#15 0x00005614be93ee3a in BackendRun (port=0x5614bfe23710) at postmaster.c:4484
        av = {0x5614bed2f4af "postgres", 0x0}
        ac = 1
#16 0x00005614be93e769 in BackendStartup (port=0x5614bfe23710) at 
postmaster.c:4206
        bn = 0x5614bfe238d0
        pid = 0
        __func__ = "BackendStartup"
#17 0x00005614be93ab8a in ServerLoop () at postmaster.c:1730
        port = 0x5614bfe23710
        i = 2
        rmask = {fds_bits = {128, 0 <repeats 15 times>}}
        selres = 1
        now = 1611651827
        readmask = {fds_bits = {224, 0 <repeats 15 times>}}
        nSockets = 8
        last_lockfile_recheck_time = 1611651827
        last_touch_time = 1611651827
        __func__ = "ServerLoop"
#18 0x00005614be93a3d9 in PostmasterMain (argc=3, argv=0x5614bfdfcd60) at 
postmaster.c:1402
        opt = -1
        status = 0
        userDoption = 0x5614bfe1f590 "data"
        listen_addr_saved = true
        i = 64
        output_config_variable = 0x0
        __func__ = "PostmasterMain"
#19 0x00005614be83949f in main (argc=3, argv=0x5614bfdfcd60) at main.c:209
        do_check_root = true

Reply via email to