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 1wRUDu-002Nva-2G for pgsql-hackers@arkaria.postgresql.org; Mon, 25 May 2026 12:15:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wRUDs-001Et2-1N for pgsql-hackers@arkaria.postgresql.org; Mon, 25 May 2026 12:15:57 +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 1wRUDs-001Esu-0E for pgsql-hackers@lists.postgresql.org; Mon, 25 May 2026 12:15:57 +0000 Received: from mail-japanwestazolkn19011012.outbound.protection.outlook.com ([52.103.66.12] helo=OS0P286CU010.outbound.protection.outlook.com) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wRUDr-00000001LOo-0K4h for pgsql-hackers@lists.postgresql.org; Mon, 25 May 2026 12:15:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TfiEN9GCbUNgvRmj56F1lfR5dOpdqlWQjWzPZuP5ML3vVj3g0qUv4K+cj/GezZzVcqgqEdVq3ffCmqO9/1L5rLiwDo+ATg52IoupiAP/gtioDPCYA8MuFl+IiiEJsXxgdclAcXVhcGvyPFoOtJiXMn/4qU87sJEkUggvrGTMoIOD4Xp9xZ/6/lr+eg4DSe0Sy1HsS+Pwo5s3gEN84VYe59vttHwI8Xi+0XRhXS7hfA17Go2jSXHUZWSDTzef2b818G8dsMm14agBw/qNBOdR//cv15178JzQeK3e+85CkEas+qTnfJbrjlqzwfTM3ZaSD5LcddwiS0QJXBGENo4+Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eqSWozll9sMMOaV//Xec1sZKAHPV2XNFrXx0XIAMB7o=; b=dPUlSTW7cSaUCZ3C6z49dsC/dtdPRqetl37biCwPCzjyxeAWD2IIA9Yo6y3yQHAeQ7ZFsO8DYYO7z+1v9VClQUcs4lc8yR70Gjzrl4oa2MXpP7M3yJrH6iUXonGyW816xvlCuwAyM8mz7dszhpPvREHf83fTu51GaNArQ51112OUPEVjNRYanW7ESH5b/sOsoZ9xSc44617/X1XgiBspXcNoePaFrRPEu4xm2oLVP/uilnfy8hw1z7eI9CQ8mdmLaHIlJ5cWpPdL8qbBJZEGrafxEY1JHfOfCrAWdD94JlgzPBx+MWYGWjUE5Mq/7jdHWH7anQPkgNynqniKli/mkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eqSWozll9sMMOaV//Xec1sZKAHPV2XNFrXx0XIAMB7o=; b=j280K2DrgmdyXl+039GWbvG9PEa47SSKADijE2+vCUyUNEk7MR3GG0Bln63b2vZKdzFZuIweqvy8GF4kGtZvBOFYAa5wka+P9C6lht5jJy2NL5J+PzbmxjuNOPKYwquP0QORWtY/BxKvxwnu9YkyiS1YSzW4l/ERv0/AaiyF1CqaD+edRO+l8JCrcGm/hZKLRaMaNSxpSXtP94myaDAj/KWI+23G+QCla7HgKP19Npdg+YPB81yJ9Qja/spzppKEDdLVyoJCkHZnaOauE6Tkt2TOVj1m52CQfvuPbQ+Fob9RcpjRz+BRQVdiys31y+ONketGC3t/24FrYVoV97NY8w== Received: from TYYPR01MB14116.jpnprd01.prod.outlook.com (2603:1096:405:212::9) by OS3PR01MB9621.jpnprd01.prod.outlook.com (2603:1096:604:1cf::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.48.19; Mon, 25 May 2026 12:15:47 +0000 Received: from TYYPR01MB14116.jpnprd01.prod.outlook.com ([fe80::31dd:4ff2:eea8:c663]) by TYYPR01MB14116.jpnprd01.prod.outlook.com ([fe80::31dd:4ff2:eea8:c663%5]) with mapi id 15.21.0048.016; Mon, 25 May 2026 12:15:47 +0000 From: Chengpeng Yan To: Alexandra Wang CC: jian he , "pgsql-hackers@lists.postgresql.org" , Tomas Vondra , Andrei Lepikhov , Corey Huinker , Tom Lane , "hs@cybertec.at" , Jeff Davis Subject: Re: Is there value in having optimizer stats for joins/foreignkeys? Thread-Topic: Is there value in having optimizer stats for joins/foreignkeys? Thread-Index: AQHcYv6ZC10TlFUn8kO0zZchsQZHS7UNRXkAgAATi4CAAFWhAIACmcGAgFirD4CAA41FgIAB6/4AgAEgywCAAGXAAICGgW0AgAB4AACAAF5OAIAKlBSAgAsxnYCAACXWAIAB8gYAgABjVACAAK2rgIAPgNKA Date: Mon, 25 May 2026 12:15:47 +0000 Message-ID: <33CC910C-8F46-444E-BE61-C9A3D157A96D@outlook.com> References: <246035.1764627115@sss.pgh.pa.us> <8df3d212-5d60-4e30-9606-d8849f7d37ae@gmail.com> <3c477f2f-10e4-4705-bb21-90ccbe67e9d2@gmail.com> In-Reply-To: Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: TYYPR01MB14116:EE_|OS3PR01MB9621:EE_ x-ms-office365-filtering-correlation-id: 1ba0c247-f3ea-4f90-f2ff-08deba575a7c x-microsoft-antispam: BCL:0;ARA:14566002|22091999003|24121999003|8060799015|24021099003|8022599003|8062599012|19110799012|15080799012|31061999003|3412199025|440099028|102099032; x-microsoft-antispam-message-info: =?us-ascii?Q?vfS727jx4nNT+1cexJfKGbm/WAQKLxjDjjUzrrlWPs3wBvRe9kmhO03xKofu?= =?us-ascii?Q?mQwlnbnZZuCzrBszcUU7avEhs5+oTKvnEtW31EEhnohd0IRjcAfeGhC9nz6U?= =?us-ascii?Q?9M/bTRYNyZMw41bYXSVJz2mI8/0G7Vje3Sk06OxJ+40aNYggDisPIb01jc6j?= =?us-ascii?Q?nbO9rs0lA9AqgzXZ2B8HcZZM0YfcOrJ1lHR5hmu4wFiT5hBfEeJjzaIz7cnb?= =?us-ascii?Q?Gl8ceduoX90/dJ3l9f28zu1OsYH/OBzq4NkSuFhB9g6XvLvmaqV4j1Y1qQMy?= =?us-ascii?Q?XhLtcnnYOSYlTKvvUyYgrtseafJqkgd0MYdmhUCX1GAauX5EF+qFW3ck2TAo?= =?us-ascii?Q?wMxYHZWhmKg33G28naZTQCuNJFsngNXBWJbtPVt9EKhQ+FDzlejFXacxgQWd?= =?us-ascii?Q?iKHhDchMxb+E5JYOTEn+/UGQiSyk4ui6SVTCnjvvbbENybZdIXPxTt+seYMt?= =?us-ascii?Q?jSuRq0C72k6HPdXjF4rvbVMi+fqmQWWBnh/qQd5lNSLUZkh7zIWBqHZkCD2c?= =?us-ascii?Q?YkoS9CwbObDJ+0hqayRymNExXNXcYjTxWgOWCba/qwVJ491lKych430IDL09?= =?us-ascii?Q?z9hGxxtqUIzFPgauQse71N2CtusAs1kz4Jejgojfj3oAhu73tp+oyW+heyV9?= =?us-ascii?Q?ZBaTnHGkJmcffvuboNf+M/M8SiKdiRJUfU9u0LF0oy4oG86GOqYFDxbWXCJz?= =?us-ascii?Q?9+fFtw5vq8twJsso1bxXPDlMPLm/6HHGcckegimKunwGpGGD0FPlKJ7H2SAV?= =?us-ascii?Q?UmcqxVDqSETp5dGi9vFKwnlsjIGiF+5BYif+dpIusJUitpP9o0pGubIniR8Q?= =?us-ascii?Q?5w6oAJ4IjdKfIVZUyTqhgagi59OmQ2ae6ubMORJIg5jZxSZLrAm1M+Jy6xtn?= =?us-ascii?Q?OkdmKZKnzyzAqvTsWqw7pfWMca46GZXO+mK+EyZI1YtC2W99m02jZDXa4spW?= =?us-ascii?Q?7Br/0hTAo/hTx8V1EN1T4Q=3D=3D?= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?insSijgg3dP4ztLAgNZcTzLfFhraeE7av5MyTohrVZl/moIgx3p2poKwGRP4?= =?us-ascii?Q?cBstUOTjr9dg00nRkCVBQNRVyHI9vk3yUhkE4bT2xWktEwlJA+TmT1wX6oe1?= =?us-ascii?Q?2HQPTGuvBXJ+FUudrN2C1H70QWRxHOcmhrsbeqGSgnc8I+9JQK7wt48elJTZ?= =?us-ascii?Q?ZoTu5PBGJ4Bf0T7C1NNEOQtXemppT4durtwxYmRSH+P8Lia+f7pxGjKi1lQn?= =?us-ascii?Q?nFYXr5IDI4IhM8E0kJl6Ymq30NixFZt3pNPpPSdl7M6mwlvCHiDNU5d5s7nV?= =?us-ascii?Q?XMWSug10Zb/Ei9/aPVqdTRIPSsitVuZ5r9lGQmu784qPu/nG4O1CuGtpC929?= =?us-ascii?Q?mSXNIaA2jUKygy+bW1Q3Ajg/PR8f/SUGRm43JGaDKOeHguLwq+fYn6+HPTa5?= =?us-ascii?Q?2psLGW6AdpXaMtJO0ITWmfAkhdJdLlE99998iEv5M7t3Q4bS0CcjC1mWOmvd?= =?us-ascii?Q?5gdKcFrLUB3N3EhM4OguaMb8otFAa6tBXCtEcTK0rzeGvtQRBl5mwxcRev2Y?= =?us-ascii?Q?90Z0JDPcRTuMn/Cy856+IeEa+twv0Sy8ohSpBltdJEcKUX2S1O4MfMnls77i?= =?us-ascii?Q?y21xW17KkVI98V+tfMbaRwm7N5WStgm5u4LrZTrvk02G4VufyRRKH6Z/rsga?= =?us-ascii?Q?KuV15g9690KqBbQQfjgPU/hbDkJHKq7MEMI6TEOBl/LZd2pq8s5kzVWXbPgy?= =?us-ascii?Q?V40lYHaWsxHFJNnqArgwiM7pKVWnJN3GhAovTQepahyp04wfACrj2BssdjbL?= =?us-ascii?Q?31pt8iC90OFEWEDZtr9Ob3Zt1POjTgfnwx28SrnSFBuNwGMUnv+ngoZw0hYy?= =?us-ascii?Q?WwVauTTDWx5lbqAyAGHT7hA2CEtxcq+gxF30utrUeOmUjw6J0ZgmfiVQ6Cmz?= =?us-ascii?Q?durygBgeRaYXZgJHqeBl/k4YyEJSfsrkVxiivv+4K+/MXIo8aa8wxWY/er+x?= =?us-ascii?Q?NDgN9aS4EzVKcNtcCx+cVRP/5SlsEc2lQNocrQzv8fh328u+Gh2Yb6C40Ksy?= =?us-ascii?Q?GRZBxCp1QSnU7rYb847wVd72H8KSIwaEb2pe8JR2xEf7WaZaVMtvFYrxkXjR?= =?us-ascii?Q?lkgAMA+v5aYxquplJk4GKcQWoJfkMr7VrZYtJ64gGMTMyvPyP7LXTnNwZL1p?= =?us-ascii?Q?CSRv5+y3XTEbdieYIlU24MN3iJY/RK0kjSXmyCzVAq+P8NuaYL65HgSvExYt?= =?us-ascii?Q?t0J9M2qVsmAIhroI1w/3M0wxPIWh1QClFpY0xU9eWLHVW5x9iQMK64yUcUQ2?= =?us-ascii?Q?JLPBQowuMSqPBBEN5d5QLfTs1XcRtr91+8zFB5CcH8eWzQG833xxaj5dB9Hl?= =?us-ascii?Q?mQ+s0Ls2FJa2H8Uw+Fr5pyD2FO2HUcGXyEzONPHz8VJDOSavYwIhXmXlBe6B?= =?us-ascii?Q?eEbayttjQeyNBQP4GaCkcedELjfkGpIdHTD/pRdEUmZaTfvG0w=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-ID: <106239790BE1884D8DAD39A2C63FC6CE@jpnprd01.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: TYYPR01MB14116.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 1ba0c247-f3ea-4f90-f2ff-08deba575a7c X-MS-Exchange-CrossTenant-originalarrivaltime: 25 May 2026 12:15:47.6039 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3PR01MB9621 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, > On May 15, 2026, at 23:30, Alexandra Wang = wrote: >=20 > Here's v7, another attempt to fix the unstable tests. Thanks for working on this. I have a few design comments about the lifecycl= e and the intended scope of the join statistic. First, the index dependency contract seems worth clarifying. CREATE STATIST= ICS records a normal dependency on the selected index, so DROP INDEX is blocked unless CASCADE is used, although that index is not part of the statistics definition. But ANALYZE appears to re-discover a suitable index when refres= hing the statistic. Is the index intended to be part of the statistic's persiste= nt contract, or only a creation-time proof that index-based sampling is possib= le? If the latter, should DROP INDEX still be blocked when another equivalent i= ndex exists? Second, this seems related to the earlier concern that ANALYZE is per-table= . The statistic is owned by the anchor relation, but its contents depend on t= he probed relation too. In the current patch, ANALYZE on the probed relation c= an refresh its own statistics without refreshing the join statistic. If the probed relation has changed substantially, that leaves a possible staleness gap where the planner combines fresh base-table statistics with stale cross-relation skew information. Third, the contract for non-unique indexes on the probed side seems worth clarifying. The comments define raw_sel as anchor-relative: P(join AND covered_filters) / anchor_totalrows, roughly Jf / anchor_totalro= ws, where Jf is the number of joined rows satisfying the covered filters. But t= he implementation computes raw_sel from MCV frequencies. Since the MCV list is built from sampled joined rows, a plain MCV frequency is naturally measured inside that joined sample, roughly Jf / J where J is the sampled join-resul= t size. It would be useful to clarify when those two quantities are expected = to be equivalent, especially when a non-unique probed-side index allows one anchor row to contribute multiple joined rows. These two measures are close in FK-like cases where the joined sample size tracks the anchor sample size. With a non-unique lookup, one anchor row may appear many times in the joined sample. For example, if one key matches man= y red rows and another key matches only one blue row, red may dominate the joined sample because of match multiplicity. That frequency describes the distribution within the joined result, but not how many matching joined row= s are produced per anchor row. It would be useful to state whether such one-to-many joins are outside the current supported scope, or how the MCV-derived raw_sel accounts for how many joined rows each anchor row contributed before it is converted into planner join selectivity. -- Best regards, Chengpeng Yan