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 1va1J4-002WrV-0h for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Dec 2025 00:40:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1va1J2-00EdyP-11 for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Dec 2025 00:40:17 +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 1va1J1-00EdyH-33 for pgsql-hackers@lists.postgresql.org; Mon, 29 Dec 2025 00:40:16 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1va1J0-0035zl-1v for pgsql-hackers@lists.postgresql.org; Mon, 29 Dec 2025 00:40:15 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2a09757004cso110833215ad.3 for ; Sun, 28 Dec 2025 16:40:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766968813; x=1767573613; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=wjEezXC1M4pXKENTdoTxECA+15yjWH11yuYNx7Jtjdg=; b=ZcUjZpxFuWhKTOM/bT99POotVkSxPbvd+eL2FUbeaMgWhn8oxJS5ZTg/XWU6KcAXif YjAg3W5STK90cGBb6FGPIN7kC/4Pl0wtEZRYav/rerJCmTciyMOeShkeK19VqERP2Ils 3maiOSPDY/mAJpNw8CbTE4BWBeotaHB2vSUsdOHhsAHnGKsZWoNa4r5cYbahld3NA0DI hHavTsqwRnBVwp0KyqyXQgMqtedqn2gKx7cAF7ANoI2xbazUMMNx+GSmProVN8PLknjX mkJY8eEx8fgfKJLl8tYqrmy2036n8bi2hG7SGTMiDRonPxvJEUJh3bDTsCwYtm2jaSzO mSXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766968813; x=1767573613; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=wjEezXC1M4pXKENTdoTxECA+15yjWH11yuYNx7Jtjdg=; b=hTrD9Y1lmft9e/Q0/4wgkun8E9R92xFgSYz5EDh+lkLkmEx7xSffFs7cV+77UC1WrE +yp0XDmOsNfnL63aihHirzvEsiwyvvdkSEOViWNatgPc9FGLTUzYnDHcd19bnw1Ff0Uq QFVTlfXYP0mCZkHq6odKsIB6vYC4a4FkJOh1RKRBZxLnXtZLMGN6HTGKjOYb38IlAZJF T+tsMYsoeSvvHnT+Qsoh5TKOCtBMfg1nk3b/MdwloYei9A8kBsJwl4HOHIO7X5ymb6MW tO4bhfhqn0IOGEF6QJj50rWJmzvsa1JE4kM5trSGDfF/CcJSXA1u6ZXFuyVg0Sdp0MX8 qdwQ== X-Gm-Message-State: AOJu0YwhQZAkmLeuqY0OikmW/AS8aQrlKnFMlsYXXt1F5+gLWTsXmCPh Dw+FoF4j8GNM+GB7czZOcZmtsKF4IJz4RShRqn3Sc2h1+G+FV/8q2HIQ++KS/alr X-Gm-Gg: AY/fxX5EAmqeIWiv2uWemCF1jnFbOV8dc515wGbxGy0l+ca/uiitH4eqOxvPGth9MHs bAR6VxCIiTlpDh9tA5yrJgOIO2er4cmJJ1u5lwq/vIiLHsgW064IgUqjlGoMADWeI98+0gCuXzN poIKxHUvujFO78T5Iz4CrAfoAcLPpMpHelYTXE5a7Rf781e9h2gbVvfPTg3JGe6MGaZEpuz/dKr oc096R3fPV629nakXJRkiDELViSKVcktwjAWk6UBklU9/bub4XuRtudNngnt6uU17ecE1op1C/d CyyetYt0BaGDp6eY4bw9v+elFAshf73wQI8NZGaT9dV0C8c69jMxFpwnZSgKsDjn+e+nVhUKBac EX8JoMeaxWesw0NekTJOmCqwE6pM0ejzR+NT7D1nb3tvMS2Aac+p36LwBPr6WhsN5CmdHagKLcW 73jnvJNu8jInjCyXnzTF6R X-Google-Smtp-Source: AGHT+IEt5XzbQWWzwMZoUKNtrfn2hUxzQShZp7MW8MgScChDP8TkQSXl1p39+dBcekE6RsuNGwRbJg== X-Received: by 2002:a05:7022:985:b0:11b:a8e3:8468 with SMTP id a92af1059eb24-121722fd206mr29985473c88.33.1766968812912; Sun, 28 Dec 2025 16:40:12 -0800 (PST) Received: from smtpclient.apple ([142.171.105.12]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-121724cfd95sm108129140c88.1.2025.12.28.16.40.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 28 Dec 2025 16:40:12 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81\)) Subject: Re: Fixing some ancient errors in hash join costing From: Chao Li In-Reply-To: <2712245.1766962600@sss.pgh.pa.us> Date: Mon, 29 Dec 2025 08:39:38 +0800 Cc: pgsql-hackers@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <705AC80B-8E3A-4DA2-9FC2-A05C4D6C70FD@gmail.com> References: <2380165.1766871097@sss.pgh.pa.us> <2551253.1766952956@sss.pgh.pa.us> <2712245.1766962600@sss.pgh.pa.us> To: Tom Lane X-Mailer: Apple Mail (2.3826.700.81) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Dec 29, 2025, at 06:56, Tom Lane wrote: >=20 > I wrote: >> I was amused to notice that the postgres_fdw.out change made in my >> patch reverts one made in aa86129e1 (which also affected semijoin >> costing). So we've had trouble before with that test case being >> fundamentally unstable. I wonder if we shouldn't do something to try >> to stabilize it? I see that the test immediately before this one >> forces the matter by turning off enable_sort (which'd affect only >> the local side not the remote). That's a hack all right but maybe >> we should extend it to this test. >=20 > Here's a v2 patchset that splits that out as a separate change for > clarity's sake. I also spent a bit of effort on commit log messages, > including researching the git history. >=20 > regards, tom lane >=20 Just a few small comments on v2: 1 - 0001 ``` -SET enable_hashjoin TO off; +-- These next tests require choosing between remote and local sort, = which is +-- a coin flip so long as cost_sort() gives the same results on both = sides. +-- To stabilize the expected plans, disable sorting locally. SET enable_sort TO off; -- subquery using stable function (can't be sent to remote) +SET enable_hashjoin TO off; -- this one needs even more help to be = stable ``` This is not a concern, just curious why switch the setting order of = enable_hashjoin and enable_sort? 2 - 0002 ``` + else if (get_attstatsslot(&sslot, vardata.statsTuple, + = STATISTIC_KIND_HISTOGRAM, InvalidOid, + 0)) + { + /* + * If there are no recorded MCVs, but we do have = a histogram, then + * assume that ANALYZE determined that the = column is unique. + */ + if (vardata.rel && vardata.rel->rows > 0) + *mcv_freq =3D 1.0 / vardata.rel->rows; + free_attstatsslot(&sslot); + } ``` As flag 0 is passed to get_attstatsslot(), free_attstatsslot() is not = needed. The function comment of get_attstatsslot states about that: ``` * Passing flags=3D0 can be useful to quickly check if the requested slot = type * exists. In this case no arrays are extracted, so free_attstatsslot = need * not be called. ``` 3 - In funciton estimate_hash_bucket_stats(), when mcv_freq is = initialized: ``` /* Look up the frequency of the most common value, if available */ *mcv_freq =3D 0.0; ``` Maybe worth adding a short comment like =E2=80=9C0.0 doesn=E2=80=99t = mean zero frequency, instead 0.0 means no data or unknown frequency=E2=80=9D= , which might help code readers to quickly understand the logic. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/