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 1vNbma-008LRa-0e for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Nov 2025 18:59:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vNbmY-003IT1-2m for pgsql-hackers@arkaria.postgresql.org; Mon, 24 Nov 2025 18:59:27 +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 1vNbmY-003ISt-1n for pgsql-hackers@lists.postgresql.org; Mon, 24 Nov 2025 18:59:26 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vNbmW-001HNP-04 for pgsql-hackers@postgresql.org; Mon, 24 Nov 2025 18:59:26 +0000 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-37b95f87d4eso36113481fa.1 for ; Mon, 24 Nov 2025 10:59:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764010763; x=1764615563; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=se4mOrRwMud/jxwHGW+xsy/sImi8G9kgwvcU/dBvwIQ=; b=Mp1ko+7AEUQNsGG1XCIwwWSw8X8+xzc1+OGEBf4n3SdPeQeJjyO+lj41O67lNw5/ZO 9Vi7aIxWVYIxqnAI+6mJxLYRne64QmIGQ0Y+I09g3zg6DVOkhpDFxTsQcRUZTpz6J5if Gw0kHkF3eKVizawx8CZAo2QZ9hMAxXuDYpEz4CPVdmb44596Ib237qPanDCUnpTyyVAz VLXduANwunOnUH93ayznKoV9onvcrXoJK8lhniWV1+04hO3TDCiwm+ay3jGvIK049hB7 iaMR9H5K7CLC7qVtePYThyhlgCoJ3+0J6VHZI1oFlv6TNFWKkzvLIIzznYuCgBFf9g9j M6GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764010763; x=1764615563; h=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=se4mOrRwMud/jxwHGW+xsy/sImi8G9kgwvcU/dBvwIQ=; b=wXEWTFsPd/DUntpYdVq5qqtp+Joc6xQAPS9XLfwLmoYnZsY14G+mECxTT5P5KTwXct 75aPqfcIB6V2t3cVlwjsiFigkM1/4D5JChahSAd107LMyTMRpOQdz3OPwiW6sZgrcVoN a56BpOhDEsoZa2XaS9MI+wYfSEU+iQI0Y1P74WCgrNYvof01/m7FWpLq1TL6vgkfu5ah PJnCn2p349YRFhCuhl/JXl9SyhVvWNI6Dqi/8d2X090z3d8c2nkoEeVQK4ZkTAd+49cx NJo+f+5qAzeUFtKWcvtfzoZl42tu8IEWzE0QWuloUOHhBSyxCgHxp6U5ZFkowz9GWCr2 nK5A== X-Gm-Message-State: AOJu0Yx02rwu4ALkk/KEWimrUlphBsGhP22of61BSfoFzPsC72YDHSzq DOao8WR2BZg5QKyrCwhwtMTYVLsERURGa4J2gSuiRULOLywki43NdXmG53/m3dH/C4r2YAXAp31 G9QP1loJywjTCSpOf7lk6jU8vzY40LP4= X-Gm-Gg: ASbGncsTA/xUC2YlRDFBxOMGasK0vbmEPfibvb2rs3aitCjAyHnK1kyhtuFf8bccYtu MgXdk7DXdWe4banEtl30aNDDnAAALoVBV+SAM3l6Lw8oVrqQcjJC2S2rByvI2/Y5ZnuV1EwoLdX s5XlxbVSHLZ3RBD4oJVuKuH6tTQaGtGttRa8SBHe8creHvOBxH4sSPiRaQpNGD+SKpVAJ3o5DW4 uyDJdb8mQVUZOPDrVG684POO3MgxdYckX4X4//zlfrK6QsJvOxO9j/Ym+EhQnh9hYg8BZ2bpawC G3fEwnvwlqoVJmPyQnBQwo9gtOU2l9OMKAYm+F75w3eCXcTbuVnqC/kD57o51QEtiPRA X-Google-Smtp-Source: AGHT+IFpUPiJvL3skumtmVbC3qlydQqjqC765OavXyJyox9YR0nY2M8PI7hyjV9dCjgCOF3NhNzXzqrobdHGZ588bBE= X-Received: by 2002:a2e:910f:0:b0:37a:3794:376 with SMTP id 38308e7fff4ca-37cd92b9ad9mr27658311fa.33.1764010762236; Mon, 24 Nov 2025 10:59:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Matthias van de Meent Date: Mon, 24 Nov 2025 19:59:10 +0100 X-Gm-Features: AWmQ_bm08SqdS5D9spnjXWzSWAjCaaLfeUrZWBQSGBthfZ52419vGP_CxfQb30g Message-ID: Subject: Re: Expanding HOT updates for expression and partial indexes To: Greg Burd Cc: "pgsql-hackers@postgresql.org" Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, 22 Nov 2025, 22:30 Greg Burd, wrote: > Thanks for pointing out the oversight for index-oriented scans (IOS), > you're right that the code in v22 doesn't handle that correctly. I'll > fix that. I still think that indexes that don't support IOS can and > should use the type-specific equality checks. This opens the door to > HOT with custom types that have unusual equality rules (see BSON). Do you have specific examples why it would be safe to default to "unusual equality rules" for generally any index's data ingestion needs? Why e.g. BSON must always be compared with their special equality test (and not datumIsEqual), and why IOS-less indexes in general are never going to distinguish between binary distinct but btree-equal values, and why exact equality is the special case here? I understand that you want to maximize optimization for specific workloads that you have in mind, but lacking evidence to the contrary I am really not convinced that your workloads are sufficiently generalizable that they can (and should) be the baseline for these new HOT rules: I have not yet seen good arguments why we could relax "datum equality" to "type equality" without potentially breaking existing indexes. HOT was implemented quite conservatively to make sure that there are no issues where changed values are not reflected in indexes: each indexed TID represents a specific and unchanging set of indexed values, in both the key and non-key attributes of indexes. If a value changes however so slightly, that may be a cause for indexes to treat it differently, and thus HOT must not be used. Aside: The amsummarizing optimization gets around that check by realizing the TID itself isn't really indexed, so the rules can be relaxed around that, but it still needs to go through the effort to update the summarizing indexes if the relevant attributes were ever so slightly updated. This patch right now wants to change these rules and behaviour of HOT in two ways: 1.) Instead of only testing attributes mentioned by indexed expressions for changes, it wants to test the output of the indexed expressions. I would consider this to be generally safe, as long as the expressions comply with the rules we have for indexed expressions. [Which, if not held, would break IOS and various other things, too, so relying on these rules isn't new or special]. 2.) Instead of datumIsEqual, it (by default) wants to do equality checks as provided by the type's default btree opclass' = operator. I have not seen evidence that this is safe. I have even explained with an example that IOS will return distinctly wrong results if only btree's = operator is used to determine if HOT can be applied, and that doesn't even begin to cover the issues related to indexes that may handle data differently from Btree. I also don't want indexes that at some point in the future invent support for IOS to return subtly incorrect results due to HOT checks that depended on the output of a previous version's amcanreturn output. So, IMV, tts_attr_equal is just a rather expensive version of datumIsEqual: the fast path cases would've been handled by datumIsEqual at least as fast (without a switch() statement with 18 specific cases and a default branch); if there is no btree operator it'll still default to btree compare, and if not then if the slow path uses correctly implemented compare operators (for HOT, and potentially all other possible indexes), then these would have an output that is indistinguishable from datumIsEqual, with the only difference the address and performance of the called function and a lot of added catalog lookups. All together, I think it's best to remove the second component of the changes to the HOT rules (changing the type of matching done for indexed values with tts_attr_compare) from this patchset. If you believe this should be added regardless, I think it's best discussed separately in its own thread and patchset -- it should be relatively easy to introduce in both current and future versions of this code, and (if you're correct and this is safe) it would have some benefits even when committed on its own. Kind regards, Matthias van de Meent