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 1vlSj6-00CZ95-1l for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Jan 2026 14:10:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vlSj5-009P4L-1a for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Jan 2026 14:10:27 +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 1vlSj5-009P4B-0B for pgsql-hackers@lists.postgresql.org; Thu, 29 Jan 2026 14:10:27 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vlSj2-002va2-25 for pgsql-hackers@lists.postgresql.org; Thu, 29 Jan 2026 14:10:26 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-b883c8dfb00so234210866b.1 for ; Thu, 29 Jan 2026 06:10:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769695824; cv=none; d=google.com; s=arc-20240605; b=lpNgIKk3DvZlRg8Bs/79m5F9ft11r7Fku4LPbByBynD0hFkTgwz1AXldGk3PR/b3im ka8eUjh/2yzHD2XsIMMUS/4bjgqtVsB8PQrataoRXAuoYjjaT8xQlnPLb3N2jkmcN1dy M80tvvrFi16p9L0RfTzu/MhE+TniVJImCueA0OP1M8j6vzBurPYcMOlnm3ezpkAMRnBQ F36VThTTJZ1BLIEh5QjYL3RUxWn3fimi8j+bZMbRLZu/JaKauGb/97ywRnUAasnUJ5vI Kk9yIYMGLS+zrwmT1Xkxsayt29ax+EcYw7aBvtsovHJQAqX5Lid5wCB5VROqOxkdFkbh etjQ== 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=mjl1au9+pr2coviir8a7OdCaoi8/WJ5fDefglOaES4c=; fh=K5Oumlx6WG4/r6luIRgO1n3jndD8Rzz5Bh1QlkxX6kA=; b=OwbZ0D+Fhgc8N2BUsutMq9rUmGKUtian3YbL9wOHWx47N9cE8ZdW469vpMesk8Sfbo aO6Orb49NHv9IhJ2PtFggNao9mjga+5X1eucs0EirgEcRPCaRZOp+vOytlN4WjyyRli5 vOx4eJ3QnwtXW3B0uzmrRG6telIM0qGreCjf+1ru12iiSYBHXGF1DexGkOs72DnatLqC aQlIieL3QL2BF9Ga3JclGWLRBbvcQ5ri70hcnHaHmiXEHZjTNoZk+QAjXG4hhcm4/xBx qcWvKEH9bjvCUmd8REAN3Bcv23ZZE41ENMbCI9hJc/KjXYWAaEw1P2WU329o0HmayXht 7fSw==; 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=1769695824; x=1770300624; 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=mjl1au9+pr2coviir8a7OdCaoi8/WJ5fDefglOaES4c=; b=WSzQSWULX9+rKmL+oa1qC1nUl8T20iHPXtMkw6qwBTHFoXEekVxjGRt69UlU60++9l 0P1QqXQiu0BpABl5eT8c5AdzxP2PMslfAV99ATO5FS4j8/wZGZAGcRuCE86lIx0W6YJl 3oOndvIwkNAaQYap1xag9romgvcZQzQR1xzBkC01EBKckeXftli5E8f8dJXqyqkFgIsu yH4U7n5anyVaaGLFHliUZyDgZJK3iq/l2T3XL8wQbJRWMUWoXJad1rgse8fmCSmwYLlE HSEWogGIwLh3h4AellSctOFA5lMOYPnRUxwa6eMvjvhJfCmh74PDYzlzRgrzb6q+PSoA IQQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769695824; x=1770300624; 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=mjl1au9+pr2coviir8a7OdCaoi8/WJ5fDefglOaES4c=; b=vy0pTItUVQRkDd83shRYHZoi2B/RiWMvdFfNUAv7lVA9l09Fn3dPTojTrHjVdVjoul rIZ+RY0PnKlgzNbvO0iAcraTterDDba+RqbL86oHhlCGpCFXRB1BtlhEs4MAk9th+xQl ffKBDJmYisoyGWP8Maw7gzl0RC1mv2GZc/M53iB1a8mnPn3+L3fFDcL2Glo9Q59U2EZo COckgyQ8GbQ+6lz5x7RkSIR42qfNIYsK25wRV+r9p266kq2n+lhfnqfHE1BcdUUi1rCB /OSxcEZndHq2djW9zyb30hBfX79v63UsFp0+kv/s4vUSD3STkFAaFLgRt7BC1iIFit8O rMbA== X-Forwarded-Encrypted: i=1; AJvYcCWuXZK29Bo+iZms47ZCOPexd3+s+60F5k4CV/NeZ7TUJbuGvIL0Pb9/QEx5Hmk1TTkd0ZTk/r4BnGZUlFS7@lists.postgresql.org X-Gm-Message-State: AOJu0YwtHHyG644V7zEFe5SNRx9W6DulrmKx9yjKoLsjMeBSM3E1MSbi ZNmnY4wwvkownuMp9S/rKKqtbQKcjoqZW/xhzwrb0noq1XnAoppIAinO+jVnkBImxSGcFhnA/Fw 1HOlmzZ2L9iP5/W860Nb8zMC6lQEp0wQ= X-Gm-Gg: AZuq6aKlBYHFQOUhBwCkI4AHm63T2+nZMBudMvrUSKIGN4KfDeL02NzVbuxZldpFMmG gBFBjkHEY5QRfiEPZ5ERYp97ZZ8xakrg2UlTVncLPW24S1r3NtIO7hcJITHfqGUyAILZsyMR+yA 88un6ahKa++hovljLhdN/E3OX5LcPhRzajwHcdvqMCQY/sFSkcDdGK0OcodthIw1qdgMH+m/YNK 7/WiI6DJvgCaVksY6sM9UCaUawaRdlntN1NLqRgAYenPOY477i+vpzWPRtuVJKafHf0UKQ3Cysk JZdWpqRmtGFfm9nKo+G7HyX5kLY= X-Received: by 2002:a17:907:98c:b0:b88:504a:f381 with SMTP id a640c23a62f3a-b8dab1bd3f0mr690540866b.23.1769695823715; Thu, 29 Jan 2026 06:10:23 -0800 (PST) MIME-Version: 1.0 References: <1136161.1769654478@sss.pgh.pa.us> In-Reply-To: From: Robert Haas Date: Thu, 29 Jan 2026 09:10:11 -0500 X-Gm-Features: AZwV_QgHxQmDKKsuCubMzPXhfXMmh1nOKDJW9km-d0rvPPFOCJz0zd-ff3q2_5s 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 1:44=E2=80=AFAM Richard Guo wrote: > I think we should access spath->disabled_nodes until after we have > verified that spath is not NULL. Good catch. I have included a fix for this in 4020b370f214315b8c10430301898ac21658143f. > Also, it's not quite clear to me why create_material_path (and > cost_material) requires the "enabled" parameter. I couldn't find any > comments on this, so it might be worth adding some comments here. 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. There are probably other ways I could have done this. For instance, we could make create_material_path() pass true to cost_material(), and not have its own "enabled" argument. That would mean that reparameterize_path() would have to unconditionally pass true. I'm not sure if that would be a problem. Another idea is to make cost_material() consult enable_material itself if path->parent is NULL, so that it wholly encapsulates the calculation locally. One thing that is a little different about materialization vs. some other operations is that it's used for multiple purposes. Sometimes we use it because it's required for correctness, and other times we do it to reduce cost. And, it can be used to affect cost in different scenarios. In the Nested Loop case, PGS_NESTLOOP_MATERIALIZE should control whether we are willing to materialize, but that doesn't apply to other cases, like build_subplan() or create_mergejoin_plan(). Moreover, these latter cases have not yet been converted to use Paths -- hopefully they will be converted someday, but maybe not soon. All of this makes things a little more complicated for materialization vs. something like a nested loop or a sequential scan, where the logic to create that thing is all in one place and paths are in use. But that is not to say that I'm deeply invested in cost_material() having an "enabled" argument -- that seems like a detail to me that could go either way. If it seems objectionable, we could change it, and I think we could probably do so in more than one way and without really affecting the behavior. Alternatively, we could leave it the way it is and add a comment clarifying whatever portion of the above you think is worth documenting in the source. It seemed like a sufficiently minor detail to me that I did not bother, but that might have been a mistake. --=20 Robert Haas EDB: http://www.enterprisedb.com