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 1wD17j-002WTe-1I for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Apr 2026 14:21:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wD17e-00HLND-31 for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Apr 2026 14:21:43 +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.96) (envelope-from ) id 1wD12z-00GWRR-2I for pgsql-hackers@lists.postgresql.org; Wed, 15 Apr 2026 14:16:54 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wCxVg-00000001CAQ-1Lsb for pgsql-hackers@lists.postgresql.org; Wed, 15 Apr 2026 10:30:18 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-b9382e59c0eso1166683666b.0 for ; Wed, 15 Apr 2026 03:30:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776249015; cv=none; d=google.com; s=arc-20240605; b=cqAQ0z+LBaPhIDiYmg9haDQCpp0+mjuDfiUwqjyATNYNC8r7FB0qaRKA4HVFlWRlmq 0XZUVVUuj+dTsqiK8Svj59IruHhvQ33dejkDSettlMOTdn18BWbTBYitBGqVnru74a5I ZzdIsKpLzr8DdGZt77Awnr8q0bSbnbjDg4gjShQUDtiw4vrFoqCleKOveaew2zruVNxT es0O4HauzwIaCEpJ1FiRH3OCex78a87iiXsdmKGSOznplmQHV5YJV9L8XNBODB4K+rU5 n6tp7e7CVgLdry6nO4O6ndgoC6SoVbDJm+qz+cbuAbGlmeyHS7TwDHfR5L79ajaSLpjn Bbcw== 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=omFW7zShWcML6do/S2lWJ/RghFje3LIepwi3k/mSEN4=; fh=YiVBu/d5gUTmKDOvc7kfQt9q2OaX0gKXxdfelPO99Cg=; b=Rz8JcvdtGcupNw2ZvgDnRrYTB3E7SnCwgIy/ehPp2SwJAmyLMFmqpfArlKR2c4ssK4 TKlIoUA9mkKuc6pMEqLGDLJ6c206AAro8gzms+zi3vnJ5r3ORdHSeDIUGNBugJCUAEPI QaAxDx6WfYb7awgKGmITq8ZmNnX+ANlrCdTanHvlDmLsNvZsSdubudZlJcsV7eG3SJEA 8bPwX4GT59eMFaJKALHoqHTKQRlLQJFEdKzvJCfE0vTmbEG2PsvT72m9QD4hNgkn3iJr ua0k9ojjkf1cXT/08WQCOS8FLKbyJJoylJkoJK0yhsiTnFncic3eFusrgX5WeaEt2hyw F8zQ==; 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=20251104; t=1776249015; x=1776853815; 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=omFW7zShWcML6do/S2lWJ/RghFje3LIepwi3k/mSEN4=; b=HegKBh8+9jcif/O1UrLbd3K5vPCNTPNBy0fL+4b3pKIMQ+2MLyHXafIYS64to5bNUR XBOl5LlIBf7o3sq3YFeE3ku3cSK+Kuar5qfMN0TQFsBNW5qD2FbUcehPjbuPcVzCZ8Zp fHWC/7EsvNOLktv2DPUyMy3zYgbLNIJYScneSnyYRMCzLXWGyBRRiRl8hbJhbKDfGbkx MXejHzXdfXb9OpoLMvjgzufilZfip4BEDl9QzjdpkZz9gs4FT3rHZlqKZnWyswS87Kzz RPYY5N8d5sO1INFAAsc68IneMyogLWJEKWj2N+72Nk35cMcaWLYPpoFnpEPGPvpidxft V8FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776249015; x=1776853815; 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=omFW7zShWcML6do/S2lWJ/RghFje3LIepwi3k/mSEN4=; b=DLaoGtHbd9Tv3tKpgBoe8J+cYz9mxsBtqPGw6SWXyJ6EsDz7PVIUIb22NyQTXYzxJF Zg8qNK0xoeoYDO88MtFZ/PtnfPZasJXKE/THuWx4+jh5+jr6UfQxwXRR4xHmcYkCWSH7 AZFNyRjO8edDKveBiWJgSF/tzpeLqcvpgr+/LBLQysq35ye6C1lPsupJDqiTsLUL9XcH jBAIalWGGobM6oGYvaZQjWdzeatAkXHMl4HIi/YMKB+k2VI3wvQb6EuozYHSzD7QGEw7 Crds3apB6yvL7NP9XBo8NqA/f/MbqRBOH+aSHZP+UcuOqJiduXswqTBaiJqL36XOl+l8 LeOA== X-Forwarded-Encrypted: i=1; AFNElJ/wG92EYnlZQy8yBypbX94cua0ZCSNKQCLZ7JtDI3PNA9klXHc6pSzCaCOJDB6LXSgryCknUujSU2D2j2XE@lists.postgresql.org X-Gm-Message-State: AOJu0Yzi+uxfkGMjAbD+xZwMo96mv9FKxaXZYE5Wv8f7ZaXZW/caoTey 32tFBzih2s+kAJb9GqmjHi9hsLEz8ydCXxEwcA3pyXV5smTb5NhEi6rSRxH8cKRExeA1RefnhoA 9bedWiUSdksN+Awz4LPdaU0886sc0/8g= X-Gm-Gg: AeBDietgcL8IvvT+vPELrq3eIE9Tjq8evXepr0aLn2b3SrJSSqyT/EDH6skmX50ojjr KVhRkHm0CQkuTBT1Oduzd23+D5HCDns9QoYLXJC6yMaYkrsjWeuz1lX28qc2ypdTaAQLb0ao11+ oLYNji2R2WgFEVmYgaV+2pUMkQWzNKLUZx7LfCaKLz0MaTrCli5IF+5M/sGvM2NQhv/hQoF2qLr 2pvXWVstOFBW/ONUh5/hxa3tnrAr+xf3FyYRtcZvQ/fY5SAEQZ+tYkY94r37la5ka9cgBBJqIVK gO/RdCfGxraRSvV1Am5LXZSK7HbMe+m+P1Ryp3HKmGrzhMrosgLpDlayl4X69w== X-Received: by 2002:a17:907:1ca5:b0:b9b:452f:fd9 with SMTP id a640c23a62f3a-b9d724c9dc7mr1287231366b.22.1776249014684; Wed, 15 Apr 2026 03:30:14 -0700 (PDT) MIME-Version: 1.0 References: <3683430.1775173413@sss.pgh.pa.us> <3817825.1775240432@sss.pgh.pa.us> <3877210.1775272486@sss.pgh.pa.us> <2672940.1775599547@sss.pgh.pa.us> In-Reply-To: From: Tender Wang Date: Wed, 15 Apr 2026 18:30:01 +0800 X-Gm-Features: AQROBzD03xWNf0tN8YX54TUYRjbbUdGZWqIyteP-IUuFFVcD0u-Ap53LsVqjIs8 Message-ID: Subject: Re: pg_plan_advice To: Alexander Lakhin Cc: Robert Haas , Melanie Plageman , Nathan Bossart , Tom Lane , Lukas Fittl , PostgreSQL Hackers , "heikki.linnakangas" 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 Alexander Lakhin =E4=BA=8E2026=E5=B9=B44=E6=9C=8815= =E6=97=A5=E5=91=A8=E4=B8=89 02:00=E5=86=99=E9=81=93=EF=BC=9A > > 13.04.2026 19:01, Robert Haas wrote: > > Sounds like we have a consensus. I have committed the three bug-fix > patches (unrelated to the retry-loop stuff) ... > > > Thanks again for committing these fixes, Robert! With all the fixes in > place, I and SQLsmith have reached another error: > CREATE TABLE t1(a int); > CREATE TABLE t2(b int); > > SELECT 1 FROM t1 WHERE EXISTS > (SELECT 1 FROM > (SELECT 1 FROM > (SELECT 1) LEFT JOIN t2 ON true), > t2 WHERE a =3D b); > > ERROR: XX000: unique semijoin found for relids (b 3 5 7) but not observe= d during planning > LOCATION: pgpa_plan_walker, pgpa_walker.c:153 > > Could you please have a look? > I did some research, and the sj_unique_rtis contains {3,5,6,7}. You can see that 6 is in the set. How 6 is added into the uniquerel->relids= . After deconstruct_jointree(), the joinlist is as follow: (gdb) call nodeToString(joinlist) $1 =3D 0x1ef1238 "({RANGETBLREF :rtindex 1} {RANGETBLREF :rtindex 7} {RANGETBLREF :rtindex 5} {RANGETBLREF :rtindex 3})" You can see that no 6 in the list. The 6 is added when processing (7, 5), in make_join_rel(), we have below lo= gic: /* * Add outer join relid(s) to form the canonical relids. Any added oute= r * joins besides sjinfo itself are appended to pushed_down_joins. */ joinrelids =3D add_outer_joins_to_relids(root, joinrelids, sjinfo, &pushed_down_joins); In this case, 6 was added to the joinrelids. When processing {1}, {3,5,6,7}, the {3,5,6,7} is the uniquerel, so in the pgpa_join_path_setup(), the {3,5,6,7} was appended to proot->sj_unique_rels. In the plan_showdown phase, in pgpa_qf_add_plan_rtis(), we can add 7, 5, and 3 to qf->relids. It seems difficult to add "6" to qf->relids when walking through the plan tree.(Maybe have an easy way, I don't know too much pg_plan_advice related code). --=20 Thanks, Tender Wang