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 1vWKmZ-00HB6E-0C for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Dec 2025 20:39:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vWKmX-004FUr-0G for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Dec 2025 20:39:29 +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 1vWKmW-004FUh-1a for pgsql-hackers@lists.postgresql.org; Thu, 18 Dec 2025 20:39:29 +0000 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vWKmV-001OCq-1a for pgsql-hackers@lists.postgresql.org; Thu, 18 Dec 2025 20:39:28 +0000 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-b7355f6ef12so204181466b.3 for ; Thu, 18 Dec 2025 12:39:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766090366; x=1766695166; 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=h+pFQs94xirQ9enPP9STJ4O1jKx9StlbeoBkZ2PPP4k=; b=I1B3DSgyM/x7wNSJOcSl2OILTUYz8sSQOFiXhug0V5p3KY5b4sbQZyufnRPtlrghpH Wc3sGmWaMQHd1V+Ob38vyGMIuFEsTDhz9ci7MiBPLE9vmkzf680I4bxuR5YZ3TAkTDh5 QkZEvWmBEabOh+ZmI0hpaNdGf4r8J30TZ0QJHu4EH8ad/fUNE9K4an9Oe0kO91LVCfyX bBOqjwnmc/0kX6cFbq6B1zYg+UOBYXFXK35c3WZLvo5pXcWzTj3Uck1vJL45I+Vmhj+j tqnTUix9KH/QFIAn12X9jMpQXnmKSv1/6CWzLdLjcNBAd05RmuyeBxNLDiM3NoFhcRie rrkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766090366; x=1766695166; 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=h+pFQs94xirQ9enPP9STJ4O1jKx9StlbeoBkZ2PPP4k=; b=mwmmkpy6UcVqTD7nkDe40mXPGAq8IaAsAUQkae1WvXaJdzEWBuTT1P2e2uO+osKp+M rvnXeuft+tEQh6AT1BSSSWV3/Ik+RvavEWWXmzBmwunqaRDHNquCxs0LDUMhaX9e20KH ySvSe+lMEwsEzpb/JRHP462FvnFN9bwcA8++KTRTy9cTaJK4hNJFG+68hKF8gLWedU85 MHC4MXHGv5KzZxAH3WZnpjgslM5nSdtjb67BGgbhO1LmRS8YXoFzVN2Vh9v+PEH5WmF3 VbYbMAkb8Jr3VdmZkIQAEtY7hRg8LzOPPYpK88vuB4V3y4Z8CpjrPWMQDyM8NzDsceSZ 0m6A== X-Forwarded-Encrypted: i=1; AJvYcCUo+yHQjclm6b2edcVFC3fGO3OJe5mcRa6NTHLXwLaTSPsStC8P9JJXy7pJ8z9kMOh5S2U8VdgXbTzrm5c7@lists.postgresql.org X-Gm-Message-State: AOJu0YzeKHaYqitBwCBzkIy3cNbNX+1a8EvhLpsDyuktjTCqIgR6RKS4 vaXBlmKlDiUK4iU38c/DenlT+nIWBrQmPUuqpe8xXhqp6ebQejhrIBCDGSaSaGcnuXmbwC4eE8K YHlh1Vzv7FT1Ue+6ksEjcyeDfLrTFnRY= X-Gm-Gg: AY/fxX5KZ0KOK78rartXrFnDB6t/Xo2IAsYKRNdKZYi7FxbhJCweSbogIzgc4QsHWFh YApvdkDQvILDtA1xGxA1EK5znLXjnp7uztOZhLhc7PKvx0MdGBn+S6e0Zd0kdBreqhI/Eyut3++ 9d6J/5PKJjBP2toujmWGMG16OcjRRiYEzv8rIP/NFVSEwj6+x5rE4Xrr06Wiv8w+KyKVY1V+ov+ eEU/AQCOSogdXvdRgehvrDcnp6ztRb4n+8z3eq+/ObXfqm2HQHwBAAVIRjEhEr60Y/u2nLI9V+G E2xm9zk/SbLfK4cPn40wwXy9ZK4= X-Google-Smtp-Source: AGHT+IFKZayK7gdNheq00qPAk170DBvTFGAYKkJ+8RSkO/Q+pLIrx/x+NzXdiY4ADKfMgCVBtMro3ywYXJl21bgQ9UM= X-Received: by 2002:a17:907:960c:b0:b77:2269:8df0 with SMTP id a640c23a62f3a-b8036f5aa2fmr69763366b.28.1766090365403; Thu, 18 Dec 2025 12:39:25 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Robert Haas Date: Thu, 18 Dec 2025 15:39:13 -0500 X-Gm-Features: AQt7F2paNCe9uVlytTYWa0Gf3AnIeecdB6yeh1APnvFoCAems2fA86O59e6u1cM Message-ID: Subject: Re: pg_plan_advice To: Jakub Wartak Cc: Jacob Champion , Dian Fay , Matheus Alcantara , 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 Wed, Dec 17, 2025 at 8:44=E2=80=AFAM Jakub Wartak wrote: > OK, now for the q10: > > Sort > Sort Key: (sum((lineitem.l_extendedprice * ('1'::numeric - > lineitem.l_discount)))) DESC > -> Finalize GroupAggregate > Group Key: customer.c_custkey, nation.n_name > -> Gather Merge > Workers Planned: 2 > -> Partial GroupAggregate > Group Key: customer.c_custkey, nation.n_name > -> Sort > Sort Key: customer.c_custkey, nation.n_name > -> Hash Join > Hash Cond: (customer.c_nationkey =3D > nation.n_nationkey) > -> Parallel Hash Join > Hash Cond: (orders.o_custkey =3D > customer.c_custkey) > -> Nested Loop > -> Parallel Seq Scan on ord= ers > Filter: > ((o_orderdate >=3D '1993-10-01'::date) AND (o_orderdate < '1994-01-01 > 00:00:00'::timestamp without time zone)) > -> Index Scan using > lineitem_l_orderkey_idx_l_returnflag on lineitem > Index Cond: > (l_orderkey =3D orders.o_orderkey) > -> Parallel Hash > -> Parallel Seq Scan on cus= tomer > -> Hash > -> Seq Scan on nation > Generated Plan Advice: > JOIN_ORDER(orders lineitem customer nation) > NESTED_LOOP_PLAIN(lineitem) > HASH_JOIN(customer nation) > SEQ_SCAN(orders customer nation) > INDEX_SCAN(lineitem public.lineitem_l_orderkey_idx_l_returnflag) > GATHER_MERGE((customer orders lineitem nation)) This looks correct to me. > but when set the advice it generates wrong NL instead of expected > Parallel HJ (so another way to fix is to simply disable PQ, yuck), > but: This is obviously bad. I'm not quite sure what happened here, but my guess is that something prevented the JOIN_ORDER advice from being applied cleanly and then everything went downhill from there. I wonder if JOIN_ORDER doesn't interact properly with incremental sorts -- that's a situation for which I don't think I have existing test coverage. > So to me it looks like in Generated Plan Advice we: > - have proper HASH_JOIN(customer nation) > - but it somehow forgot to include "HASH_JOIN(orders)" to cover for > that Parallel Hash Join on (orders.o_custkey =3D customer.c_custkey) > with input from NL. After adding that manually, it achieves the same > input plan properly. The first table in the JOIN_ORDER() specification isn't supposed to have a join method specification, because the join method specifier says what appears on the inner, i.e. second, arm of the join. --=20 Robert Haas EDB: http://www.enterprisedb.com