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.96) (envelope-from ) id 1volQX-00DUGE-2f for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Feb 2026 16:44:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1volQW-006yuK-1r for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Feb 2026 16:44:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1volQW-006yuC-0U for pgsql-hackers@lists.postgresql.org; Sat, 07 Feb 2026 16:44:56 +0000 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1volQT-000000010rF-2c3a for pgsql-hackers@lists.postgresql.org; Sat, 07 Feb 2026 16:44:54 +0000 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-6581234d208so2823268a12.3 for ; Sat, 07 Feb 2026 08:44:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770482692; cv=none; d=google.com; s=arc-20240605; b=X5n5OGVUI/OBSuHdiGntButITkq5KO4LmxKSVvVQAKwazxQH7fjNuUIDH2xAJwkzjo hJQbXpHU8uL1Bvmq2HgL0dtjWiRDnjuklT5NehOCnvrwe20PQHcCDcO0vCSUSzDv2A7i CszhCr03o0SM71+yopXoMYrsCyoL6LoZ0YiZ8N+as2fJh50bIECyzLmx/MnTqBB9X3+K Bf6nayULmG6fbTVPdSJ4xomQiL2ikFdPcPvggnebgLuIzTaq+PBga5jRs9ToErMWV8vg 366Kw/8xg0FnLwiEJ8Cam0mqKFdU7zW3Z3DjjmC64yGPwQJvioW8l+3oP2yY6nC38GgB nCAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bvrFzpRgmqlGaNldUZnohi8qY7b9JL1WvM1QHEB2GNI=; fh=tfocSYv0GGNgWySKFV4SYHRr2DjrEzO7omzyBoMMwHw=; b=Uy9vCM1kOOltU1NPIMqaap2B+OGc5KrLknh/j30vktnAPkFoDHgJV5ta8bK0rsg6Zo yGBj7ABDvCqOgiJL3WjgpDTb5JEDaTy8nLIWd/DcYrG3hHAkVT908DDg0JuveHh3feMI P4W+y/nmtBFkCn1SIMBLEevMcbNDpSLmCSOZv/P58Id1UxUGHhwwaiEsEGevoA7ipdgl 5RJcNg7Ko4aNXERnA28gB6sgbFJgE0BYqe+MGO26IiTFxE50kDWQdPaeN9kXroc0Ra9r NftvHegV02+UZajmI2KVt0512BXqQjNhJXe6duDxcugtrHOoVnEurCvVXO1xUohKnKF2 XYoA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770482692; x=1771087492; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bvrFzpRgmqlGaNldUZnohi8qY7b9JL1WvM1QHEB2GNI=; b=FsW1kv3vpkdQLAjWrLv0cz3qJpQlUzvjbDevOMNIlSatgWvbSSBVKCLNO6fG3NFPji 9pliSlzCBnnuw4KDNHDDl8q/IHu7AyVlAuUd6/COt12p87D47uc1cY9N4IAsXsoJd2fx ff2+CAi/TdSjhjWGpjA6dxV6LHHJhmlQEaHm9ULjzEMa3nilX6+cXbG5l/EpUdoD6t1T +bIpiKFby+A+cylBjaq22/aogNAI71Knn1LttPHQEViR7mRyjCjAaxTuoJhQEVMLyvsF gIdho2hMVGNggA1UOj9osSeH3IRwb1Qg3Ql8THNw4Vr3rk0UW2fBE0ynEGZD4knkQMRO 9V7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770482692; x=1771087492; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bvrFzpRgmqlGaNldUZnohi8qY7b9JL1WvM1QHEB2GNI=; b=Kmu5YzfgPAKklF7cYxAOkYAzsAPnG5gJUxJYg1xZzwF2wvDYkW4QtlBxrz0Eb6QRew 4AbPmesph8ISCWwwoHE2D/6L1rLl1lJRaudMEQkORiLysmTqlpvOXckQHv4ISXp4NDFt I1NBt6wsjq3D2dP8Wq3Rbct9Uq+J+cz5J8GT0DftFek9kqr4ZPGSJi/ldvuu6IL/e5Uf Op19PaUvhc9wBztUtYu1KyD7VnbwCBZ2pzAmwn76Qxa+adz4whTNdLRzQqzn7O3bTMGK o/+hOgcAECxiUl9jXfuK96bduGq/inqve2rdL1EI7nWqXc4rM9Qo5O7z0DW5SqpSUd5m HD5g== X-Forwarded-Encrypted: i=1; AJvYcCVbHXiNlII3958ZitOM3cgNtUR10YvgUKd7jN5YcvIXvkRZ9+KRxp5J7LapW6peEoxOtOHlR/BvFO9ZzpwQ@lists.postgresql.org X-Gm-Message-State: AOJu0Yy7wTzXuv0eRAzmu23xiR2DZTIBgTAnL5ggIa6PGlmVAftenutR Dt+ddA43iHufWUUuXUZqagkDW8GkkU7IyJZYaXI4kxFFfz+5Yf62nQqMEPjYFORtuoAUlLFpITc CZeQR1eVTsD5g9iaZcUdBSqbgpetfKAk= X-Gm-Gg: AZuq6aL1uDZ+5hFFLEMhUdn5oDp/PmjXzolayHl/XvLamN+GVOXRCMhZNIsOY3+tXp/ bg5Np9X5j4oL5SLBFU2/jAdSZXWVRUoV0vX+QTLj9bENX8al8/Yu+RBALZmyJ3sodBuiwTaa2hh YBrgs2KfRSUERtOTcrLvTAV5FIVmgMmZnAC+QqwYlp4AmiWGvZdkHCLXl3xAZo4ZtqQI4jONSjY LZwW+r2f7Vq8L07BsSkxbW6mMtdxUWjfSc8ZBA6YN6Jl60I5faIdRIahI5lU+YupVUEuvH5EXV+ C8uV2/meuVQt2BYqSsFYCDet3oLnSbjpgGAf/w== X-Received: by 2002:a17:906:f594:b0:b88:463e:b55f with SMTP id a640c23a62f3a-b8edf15f0fcmr306858566b.6.1770482691682; Sat, 07 Feb 2026 08:44:51 -0800 (PST) MIME-Version: 1.0 References: <1136161.1769654478@sss.pgh.pa.us> In-Reply-To: From: Robert Haas Date: Sat, 7 Feb 2026 11:44:39 -0500 X-Gm-Features: AZwV_QhEKDqyXuTehGAk7BP_AEu-R3uP5iyCPfWgbeUiiicthwoF0-wDWkpChzY Message-ID: Subject: Re: pg_plan_advice To: Richard Guo Cc: Lukas Fittl , Tom Lane , Jacob Champion , Dian Fay , Matheus Alcantara , Jakub Wartak , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jan 29, 2026 at 9:10=E2=80=AFAM Robert Haas = wrote: > I think cost_material() got an enabled argument because of > materialize_finished_plan(). Most of the time, plan nodes are created > from paths, and we want to use the parent's pgs_mask to determine > whether the chosen strategy (e.g. materialization) is enabled. > However, materialize_finished_plan() creates a plan directly, so > there's no RelOptInfo or JoinPathExtraData whose pgs_mask we can > consult, and so we have to fall back on consulting enable_material > directly. Once that parameter got added to cost_material(), it made > sense to me to add it to create_material_path() as well. If this explanation seems a little weak, it's because it was. Here's a better explanation: the patch added a per-rel flag PGS_NESTLOOP_MATERIALIZE that enables the use of a Nested Loop join with an inner Materialize node. When we construct such a path, the "parent" point for the materialize path points to the rel that is on the inner side of the join, not the joinrel itself. But the pgs_mask flags of the joinrel and its inner side could be different. Therefore, the Materialize node can't just look at path->parent->pgs_mask to decide whether to mark the node as disabled. So, when I wrote the patch originally, I added an enabled flag here to make sure that we pass down the information about whether the join method was enabled at the joinrel level, since the joinrel's pgs_mask is not otherwise available to cost_material(). Later on, I discovered the need for PGS_CONSIDER_NONPARTIAL, but by then I had forgotten why that "enabled" argument existed and pushed the logic to handle PGS_CONSIDER_NONPARTIAL into cost_material(). So the logic as currently committed is buggy in the case where the joinrel and the innerrel have differing pgs_mask values. match_unsorted_outer() and consider_parallel_nestloop() have the intention of generating Materialize nodes only when materialization is enabled, so that the Materialize nodes are never marked disabled. But with the patch as committed, a non-partial Nested Loop with inner Materialize can disable the Materialize node if the inner rel's pgs_mask has PGS_CONSIDER_NONPARTIAL unset. The right fix is to make all the decisions about whether the Materialize nod should be created, and whether it should be enabled, in the caller, and have none of that logic in cost_material(). I will post a new patch set shortly, which will include a patch to rectify this issue. --=20 Robert Haas EDB: http://www.enterprisedb.com