Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qdTeM-003YiU-PD for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Sep 2023 10:51:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qdTeL-0016OI-46 for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Sep 2023 10:51:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qdTeK-0016OA-Q1 for pgsql-hackers@lists.postgresql.org; Tue, 05 Sep 2023 10:51:12 +0000 Received: from mail-yb1-xb31.google.com ([2607:f8b0:4864:20::b31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qdTeH-003Aun-8w for pgsql-hackers@lists.postgresql.org; Tue, 05 Sep 2023 10:51:11 +0000 Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-d77ad095f13so1680786276.2 for ; Tue, 05 Sep 2023 03:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693911067; x=1694515867; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=z/kldgDoM0WtYF6EMgn9wg+iO8j13uGRvS0Pci+l3g4=; b=H82mTBL9ahfvPaTFZwQVjdF+g2npvfBwM2fKxjUXE69U/piqJyXGTaMx4ygcyl0qK8 oVCChDxxf1wbJLeIB9Ocl7gElVLDc2VBNrMRTxKE/vgQEov07ISfNvDBnwaLoTS/feR9 jSYyTjvFpx8Wo8vSzNLNq4WnHJroz66ij8/FWfZB5vvp4VHZLhSo5rOCOjx0Vu6UXLE9 y+Gya1EnvAfnvVDWNY+Q+79bLBv4tGE6n3w03CZdUTcvzFKijYPmEIBgB9NyWlrAIWN/ 1UBU8VeYYHnO4VTsPQAR8lmeCHJwFQEM9S/kGZ6zeYIPxL+ODH5Gh3RexFwQhYq8GX9v jq8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693911067; x=1694515867; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=z/kldgDoM0WtYF6EMgn9wg+iO8j13uGRvS0Pci+l3g4=; b=XaJH/ggg2cA4piYkzoFAMA1MAwaixbU4knbScOlvyB3M7FTHNeeaacsoUEg+X4Uav2 qTaMnJgkBCyyXYfY4eTiP4Iv1i6pzua1lCYeKG1OEqYrri3p6VKS0VRYCVKy0qYERs01 y0LbSpQ+S4BVXJ/onnmOESj/rJGL9YpnlYzr53jZaCG/XXUBV04hsmKkxBc7VIjZyqdD nK47xg20EOcja4orLHYoBGue5fYCxO86Wplztgb3WXm848JKTmLopmQ3SnrF/O4beDdp RQVXFeBhEdqMGHMn50MoE9wo1kjok5mENKaTASoQXyFqWZpVheyriVOyoGJtdjk63H7X YQnw== X-Gm-Message-State: AOJu0Yw4XG0SzNmtMilDSjOpr3vSueavy2UWb2DwzKF4hLLDmQCGTUBD eVezbsEYRvXouKXcyEDiQBKXMJkNGKeEhlqdZZU= X-Google-Smtp-Source: AGHT+IGcXVZLPZyvFWXEteYu5qzpzyZisaKHnCCP7LufCw++E3X4qmrbUp7lTvT264uakNUPghyGJArf7/TSBS6f3Gk= X-Received: by 2002:a25:1085:0:b0:d78:2cdc:4d2 with SMTP id 127-20020a251085000000b00d782cdc04d2mr11379400ybq.6.1693911067458; Tue, 05 Sep 2023 03:51:07 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Guo Date: Tue, 5 Sep 2023 18:50:56 +0800 Message-ID: Subject: Re: Should consider materializing the cheapest inner path in consider_parallel_nestloop() To: tender wang Cc: pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000075003e06049a67bf" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000075003e06049a67bf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Sep 5, 2023 at 4:52=E2=80=AFPM tender wang wro= te: > I recently run benchmark[1] on master, but I found performance problem > as below: > ... > > I debug the code and find consider_parallel_nestloop() doesn't consider > materialized form of the cheapest inner path. > Yeah, this seems an omission in commit 45be99f8. I reviewed the patch and here are some comments. * I think we should not consider materializing the cheapest inner path if we're doing JOIN_UNIQUE_INNER, because in this case we have to unique-ify the inner path. * I think we can check if it'd be parallel safe before creating the material path, thus avoid the creation in unsafe cases. * I don't think the test case you added works for the code changes. Maybe a plan likes below is better: explain (costs off) select * from tenk1, tenk2 where tenk1.two =3D tenk2.two; QUERY PLAN ---------------------------------------------- Gather Workers Planned: 4 -> Nested Loop Join Filter: (tenk1.two =3D tenk2.two) -> Parallel Seq Scan on tenk1 -> Materialize -> Seq Scan on tenk2 (7 rows) Thanks Richard --00000000000075003e06049a67bf Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Tue, Sep 5, 2023 at 4:52=E2=80=AFPM te= nder wang <tndrwang@gmail.com&= gt; wrote:
=C2=A0 =C2=A0I recently=C2=A0run benchmark[1] on master, but = I found performance=C2=A0problem as below:
...

I debug the code and find consider_parallel_nestloop() doesn't c= onsider materialized form of the cheapest inner path.

Yeah, this seems an omission in commit 45be99f8.=C2= =A0 I reviewed the patch
and here are some comments.

* I think we= should not consider materializing the cheapest inner path
=C2=A0 if we&= #39;re doing JOIN_UNIQUE_INNER, because in this case we have to
=C2=A0 u= nique-ify the inner path.

* I think we can check if it'd be para= llel safe before creating the
=C2=A0 material path, thus avoid the creat= ion in unsafe cases.

* I don't think the test case you added wor= ks for the code changes.
=C2=A0 Maybe a plan likes below is better:
<= br>explain (costs off)
select * from tenk1, tenk2 where tenk1.two =3D te= nk2.two;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = QUERY PLAN
----------------------------------------------
=C2=A0Gathe= r
=C2=A0 =C2=A0Workers Planned: 4
=C2=A0 =C2=A0-> =C2=A0Nested Loo= p
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Join Filter: (tenk1.two =3D tenk2.tw= o)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-> =C2=A0Parallel Seq Scan on te= nk1
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-> =C2=A0Materialize
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-> =C2=A0Seq Scan on ten= k2
(7 rows)

Thanks
Richard
--00000000000075003e06049a67bf--