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.94.2) (envelope-from ) id 1tpyKk-00F0LV-C4 for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Mar 2025 23:39:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tpyKi-009Gh6-Vv for pgsql-hackers@arkaria.postgresql.org; Wed, 05 Mar 2025 23:39:25 +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.94.2) (envelope-from ) id 1tpyKi-009Ggy-Lh for pgsql-hackers@lists.postgresql.org; Wed, 05 Mar 2025 23:39:24 +0000 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tpyKd-001C4L-0W for pgsql-hackers@postgresql.org; Wed, 05 Mar 2025 23:39:23 +0000 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-30bcb48b0a4so239751fa.2 for ; Wed, 05 Mar 2025 15:39:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741217958; x=1741822758; darn=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=vlXJRjNsYsL4jAU8Z86zGZEpUX5YcoAOxIPQDzscDk0=; b=k/ZW9ggI83aOnLMRcmXN/5HYl5eBgFCM5bgMjdQBWovaoQWILhARK+7K4X7eCLShRe wXz3uKcxB4FVz0LoldvIVxTxUZkllIXjcMvXxOlSTUpLHcmpHuL4ZV9SN7nRq8C6L9NQ BSHY/eRXQ8aupG4CfykfkVC54xZfR41VHlgiN7/R3BkbsCGhr9buvLI8VHuOhO+FVIhd zVBNtiLq5xS8+PUwJyKsVQoG/lW3A+5BZTvnE+2TDO02lagRLk2rWBFPPtJplRjzT5jv BANCMAtMCQPMbqkUD3kM7I8rRFGxqj9IerNDtAkYW/ENPjzvA1hzPGwHb2Keh5gtkApG Jnow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741217958; x=1741822758; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vlXJRjNsYsL4jAU8Z86zGZEpUX5YcoAOxIPQDzscDk0=; b=PW+wng37eL/fgLxBfeDe2WatBGqMi4XYZ4Pnqw7ghQ6lb4IvHhke6tKhCMfCHyD4oE YY9wOvBhLMSiltegUiOg1wxJxCLOxbqWOTxLhl3QjQZmFWfAedakm5ppoiVf+Jk5J2eq zN0eU6Qa7Ckb9nuR3xSuCbYo0xc5EEliH/Mi5Pkyjy3jYaPxIeYOYOVN2P96J7db9t6P YCEvoCRtR7wLuiPYc0TNcwk4v9mhwQ64IPH6F4BMCVqxUtywDLpsFdWgENEhD5sDcat2 al8+knxskdZD3a1eo6p06J1NzIEP2r+UZKsII6EStggYzV67fbs1baOszR1ooW6UHZcw sY1w== X-Gm-Message-State: AOJu0YySrh6SLlNBEyUM8YuKdGoD9y9D8jPoByGplEBhA5prSztud8ie z5JlRDnIZXBINQUXxKZrMw1Lmkah834kav6YoxAprBt38JgOgZ64l1aTScpw31+XUChxFg1bBey N5bSsemeubUlySuojlNIhJxt7H29TY5dOB7s= X-Gm-Gg: ASbGncu26J9oVTDNrCezomZ4dN9BrZUcg/jpKCe0fJmVnMwNV7sMJYYUlfsj7awaC/0 407ukLm+gaVHpmmasqaK47EdVXilPrQ/tyZMfwEv4nhcFVWjvHsODys3RUIfIsw1k6iiZXmlo2l aIqjGlXvrOjo5y0MdYGTEAl2RZUg== X-Google-Smtp-Source: AGHT+IG0Ju6kco6ba/xvra6WftSQ8QaIchsmW9ayQn8QtwlumD7C78/f0SHP5kqwjuFcJvKIoIHdbA3Pvh7D2FOpAP8= X-Received: by 2002:a05:651c:2125:b0:308:f5f0:c438 with SMTP id 38308e7fff4ca-30bd7b122fbmr18371951fa.31.1741217957414; Wed, 05 Mar 2025 15:39:17 -0800 (PST) MIME-Version: 1.0 References: <78574B24-BE0A-42C5-8075-3FA9FA63B8FC@amazon.com> <238EEE41-B206-4590-8C20-DA52C25A2291@amazon.com> <51C77060-059F-4BB3-8EAF-83F08656F6D2@amazon.com> In-Reply-To: <51C77060-059F-4BB3-8EAF-83F08656F6D2@amazon.com> From: Matthias van de Meent Date: Thu, 6 Mar 2025 00:39:03 +0100 X-Gm-Features: AQ5f1JqXe-ninZVPobb4NIjTlHEUf5iKpoG-4ZnXh-6GtbfJdAf0G_inuTL6jFw Message-ID: Subject: Re: Expanding HOT updates for expression and partial indexes To: "Burd, Greg" Cc: "pgsql-hackers@postgresql.org" 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, 5 Mar 2025 at 18:21, Burd, Greg wrote: > > Hello, > > I've rebased and updated the patch a bit. The biggest change is that the= performance penalty measured with v1 of this patch is essentially gone in = v10. The overhead was due to re-creating IndexInfo information unnecessari= ly, which I found existed in the estate. I've added a few fields in IndexI= nfo that are not populated by default but necessary when checking expressio= n indexes, those fields are populated on demand and only once limiting thei= r overhead. This review is based on a light reading of patch v10. I have not read all 90kB, and am unlikely to finish a full review soon: > * assumes estate->es_result_relations[0] is the ResultRelInfo being updat= ed I'm not sure that's a valid assumption. I suspect it might be false in cases of nested updates, like $ UPDATE table1 SET value =3D other.value FROM (UPDATE table2 SET value =3D 2 ) other WHERE other.id =3D table1.id; If this table1 or table2 has expression indexes I suspect it may result in this assertion failing (but I haven't spun up a server with the patch). Alternatively, please also check that it doesn't break if any of these two tables is partitioned with multiple partitions (and/or has expression indexes, etc.). > * uses ri_IndexRelationInfo[] from within estate rather than re-creating = it As I mentioned above, I think it's safer to pass the known-correct RRI (known by callers of table_tuple_update) down the stack. > * augments IndexInfo only when needed for testing expressions and only on= ce ExecExpressionIndexesUpdated seems to always loop over all indexes, always calling AttributeIndexInfo which always updates the fields in the IndexInfo when the index has only !byval attributes (e.g. text, json, or other such varlena types). You say it happens only once, have I missed something? I'm also somewhat concerned about the use of typecache lookups on index->rd_opcintype[i], rather than using TupleDescCompactAttr(index->rd_att, i); the latter of which I think should be faster, especially when multiple wide indexes are scanned with various column types. In hot loops of single-tuple update statements I think this may make a few 0.1%pt difference - not a lot, but worth considering. > * only creates a local old/new TupleTableSlot when not present in estate I'm not sure it's safe for us to touch that RRI's tupleslots. > * retains existing summarized index HOT update logic Great, thanks! Kind regards, Matthias van de Meent Neon (https://neon.tech)