Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lnWHL-00076w-Vg for pgsql-bugs@arkaria.postgresql.org; Mon, 31 May 2021 00:59:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lnWHJ-00069N-Dp for pgsql-bugs@arkaria.postgresql.org; Mon, 31 May 2021 00:59:37 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lnWHJ-00069E-7D for pgsql-bugs@lists.postgresql.org; Mon, 31 May 2021 00:59:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lnWHC-0006Ks-Kl for pgsql-bugs@lists.postgresql.org; Mon, 31 May 2021 00:59:36 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 14V0xSVm2491425; Sun, 30 May 2021 20:59:28 -0400 From: Tom Lane To: Dmitry Dolgov <9erthalion6@gmail.com> cc: "Poot, Bas (B.J.)" , "pgsql-bugs@lists.postgresql.org" Subject: Re: XX000: unknown type of jsonb container. In-reply-to: <2433209.1622416353@sss.pgh.pa.us> References: <534fca83789c4a378c7de379e9067d4f@politie.nl> <20210407181105.lmi7hgifwzs3eeee@localhost> <20210413161500.kufk4iyrmcmhhbrc@localhost> <20210423151505.lxx5ti7ivcza3xqw@localhost> <2433209.1622416353@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sun, 30 May 2021 19:12:33 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <2491408.1622422747.0@sss.pgh.pa.us> Date: Sun, 30 May 2021 20:59:28 -0400 Message-ID: <2491424.1622422768@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2491408.1622422747.1@sss.pgh.pa.us> I wrote: > I'm not sure about creating a test case. The case reported here is > far too expensive to use in the regression tests. Ah, we can do it in select_parallel, which reduces all the parallel costs to zero to favor these sorts of plans. This test case only fails back to v13, as does the original example. I suspect we should back-patch the code change further though, since create_projection_plan will be just as confused by such cases in earlier branches. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="remove-redundant-ProjectionPath-2.patch"; charset="us-ascii" Content-ID: <2491408.1622422747.2@sss.pgh.pa.us> Content-Description: remove-redundant-ProjectionPath-2.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer= /util/pathnode.c index b248b038e0..9ce5f95e3b 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -2632,7 +2632,23 @@ create_projection_path(PlannerInfo *root, PathTarget *target) { ProjectionPath *pathnode =3D makeNode(ProjectionPath); - PathTarget *oldtarget =3D subpath->pathtarget; + PathTarget *oldtarget; + + /* + * We mustn't put a ProjectionPath directly above another; it's useless + * and will confuse create_projection_plan. Rather than making sure all + * callers handle that, let's implement it here, by stripping off any + * ProjectionPath in what we're given. Given this rule, there won't be + * more than one. + */ + if (IsA(subpath, ProjectionPath)) + { + ProjectionPath *subpp =3D (ProjectionPath *) subpath; + + Assert(subpp->path.parent =3D=3D rel); + subpath =3D subpp->subpath; + Assert(!IsA(subpath, ProjectionPath)); + } = pathnode->path.pathtype =3D T_Result; pathnode->path.parent =3D rel; @@ -2658,6 +2674,7 @@ create_projection_path(PlannerInfo *root, * Note: in the latter case, create_projection_plan has to recheck our * conclusion; see comments therein. */ + oldtarget =3D subpath->pathtarget; if (is_projection_capable_path(subpath) || equal(oldtarget->exprs, target->exprs)) { diff --git a/src/test/regress/expected/select_parallel.out b/src/test/regr= ess/expected/select_parallel.out index 05ebcb284a..4ea1aa7dfd 100644 --- a/src/test/regress/expected/select_parallel.out +++ b/src/test/regress/expected/select_parallel.out @@ -1126,6 +1126,29 @@ ORDER BY 1, 2, 3; ------------------------------+---------------------------+-------------+= -------------- (0 rows) = +EXPLAIN (VERBOSE, COSTS OFF) +SELECT generate_series(1, two), array(select generate_series(1, two)) + FROM tenk1 ORDER BY tenthous; + QUERY PLAN = +---------------------------------------------------------------------- + ProjectSet + Output: generate_series(1, tenk1.two), (SubPlan 1), tenk1.tenthous + -> Gather Merge + Output: tenk1.two, tenk1.tenthous + Workers Planned: 4 + -> Result + Output: tenk1.two, tenk1.tenthous + -> Sort + Output: tenk1.tenthous, tenk1.two + Sort Key: tenk1.tenthous + -> Parallel Seq Scan on public.tenk1 + Output: tenk1.tenthous, tenk1.two + SubPlan 1 + -> ProjectSet + Output: generate_series(1, tenk1.two) + -> Result +(16 rows) + -- test passing expanded-value representations to workers CREATE FUNCTION make_some_array(int,int) returns int[] as $$declare x int[]; diff --git a/src/test/regress/sql/select_parallel.sql b/src/test/regress/s= ql/select_parallel.sql index d31e290ec2..f924731248 100644 --- a/src/test/regress/sql/select_parallel.sql +++ b/src/test/regress/sql/select_parallel.sql @@ -429,6 +429,10 @@ ORDER BY 1; SELECT * FROM information_schema.foreign_data_wrapper_options ORDER BY 1, 2, 3; = +EXPLAIN (VERBOSE, COSTS OFF) +SELECT generate_series(1, two), array(select generate_series(1, two)) + FROM tenk1 ORDER BY tenthous; + -- test passing expanded-value representations to workers CREATE FUNCTION make_some_array(int,int) returns int[] as $$declare x int[]; ------- =_aaaaaaaaaa0--