Re: Parallel Inserts in CREATE TABLE AS - Mailing list pgsql-hackers

From Bharath Rupireddy
Subject Re: Parallel Inserts in CREATE TABLE AS
Date
Msg-id CALj2ACUw4=14F4TFKb-p+2EDoWJpobto_jESx9qzA8C-QSVpxQ@mail.gmail.com
Whole thread Raw
In response to RE: Parallel Inserts in CREATE TABLE AS  ("Hou, Zhijie" <houzj.fnst@cn.fujitsu.com>)
Responses Re: Parallel Inserts in CREATE TABLE AS
List pgsql-hackers
On Tue, Dec 15, 2020 at 5:48 PM Hou, Zhijie <houzj.fnst@cn.fujitsu.com> wrote:
> > A little explanation about how to push down the ctas info in append.
> >
> > 1. about how to ignore tuple cost in this case.
> > IMO, it create gather path under append like the following:
> > query_planner
> > -make_one_rel
> > --set_base_rel_sizes
> > ---set_rel_size
> > ----set_append_rel_size (*)
> > -----set_rel_size
> > ------set_subquery_pathlist
> > -------subquery_planner
> > --------grouping_planner
> > ---------apply_scanjoin_target_to_paths
> > ----------generate_useful_gather_paths
> >
> > set_append_rel_size seems the right place where we can check and set a flag
> > to ignore tuple cost later.
> > We can set the flag for two cases when there is no parent path will be
> > created(such as : limit,sort,distinct...):
> > i) query_level is 1
> > ii) query_level > 1 and we have set the flag in the parent_root.
> >
> > The case ii) is to check append under append:
> > Append
> >    ->Append
> >        ->Gather
> >    ->Other plan
> >
> > 2.about how to push ctas info down.
> >
> > We traversing the whole plans tree, and we only care Append and Gather type.
> > Gather: It set the ctas dest info and returned true at once if the gathernode
> > does not have projection.
> > Append: It will recursively traversing the subplan of Appendnode and will
> > reture true if one of the subplan can be parallel.
> >
> > +PushDownCTASParallelInsertState(DestReceiver *dest, PlanState *ps) {
> > +     bool parallel = false;
> > +
> > +     if(ps == NULL)
> > +             return parallel;
> > +
> > +     if(IsA(ps, AppendState))
> > +     {
> > +             AppendState *aps = (AppendState *) ps;
> > +             for(int i = 0; i < aps->as_nplans; i++)
> > +             {
> > +                     parallel |=
> > PushDownCTASParallelInsertState(dest, aps->appendplans[i]);
> > +             }
> > +     }
> > +     else if(IsA(ps, GatherState) && !ps->ps_ProjInfo)
> > +     {
> > +             GatherState *gstate = (GatherState *) ps;
> > +             parallel = true;
> > +
> > +             ((DR_intorel *) dest)->is_parallel = true;
> > +             gstate->dest = dest;
> > +             ps->plan->plan_rows = 0;
> > +     }
> > +
> > +     return parallel;
> > +}
>
> So sorry for my miss, my last patch has some mistakes.
> Attatch the new one.

Thanks for the append patches. Basically your changes look good to me.
I'm merging them to the original patch set and adding the test cases
to cover these cases. I will post the updated patch set soon.

With Regards,
Bharath Rupireddy.
EnterpriseDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: "Hou, Zhijie"
Date:
Subject: RE: Parallel Inserts in CREATE TABLE AS
Next
From: Amit Kapila
Date:
Subject: Re: [HACKERS] logical decoding of two-phase transactions