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 1vziZg-001Fae-0U for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2026 21:55:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vziZc-000r83-2e for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2026 21:55:37 +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 1vziZc-000r7u-1b for pgsql-hackers@lists.postgresql.org; Mon, 09 Mar 2026 21:55:37 +0000 Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vziZa-00000001s29-08zB for pgsql-hackers@lists.postgresql.org; Mon, 09 Mar 2026 21:55:36 +0000 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-7985ce90542so117260727b3.0 for ; Mon, 09 Mar 2026 14:55:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773093332; cv=none; d=google.com; s=arc-20240605; b=SrY4PHyah7NfZhzZ/almggfGZ0RBvgsHSJ81gl/DbzmU6+ZcOLpdWwibzi1z0LuBKa Ykj7lBqMBI34e8ABhswNaqRC2UlcXeQeVncgttUvwrvezt/7/uN/y7oXGvkwD4otiknH xivJQ5lAQPJlYbpVuSuBQ6mK2gyVfQOWvrmhm6RviR07YEslTllRieaaPy4tGzofqnX3 vbY3G/GS6C11mgWEUjwlO2bVuse1ak5U7MSdgrVfoitQ+ItQnmFfrr0w45w0FpjMNfZS sgl37q3ESRK8QrTXIM819caZstbnuPOqXT0rZfSDAcsquRJw5j2R31KAWFv6UydnPvFd IHGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=Kwe6UtWyx2OVuW6T083mQimPhpVfcse2SiONat5M5AA=; fh=KNbHZHkP1tt5t8UvibSexJtEF5PUbw0pfTUvfDM7Gw8=; b=a9xhaUVx40GhV82fayjWCsvNQx3r76scTddAYAFGwVwXjMZ3pOuNqbMKcot2mTKsco hBYStFnSVIMpUjQlNAD0s6iiBYqMjE5I/MVhW0msrf7c/x+1TuzVIokZBwNM11VpRX+n LFpb2vN7OoRCU/Mai01sQlZLMSxaSniH+RaaPMmqw/YFHVZYamEOB1Q8IhFW8lgFhF9j Eulqlm2JUOasgy5Kke0zr6wucia57m6w8iBwfXp8A1R2AkWiRaWt7bu7WjgbX+Amk5ut XzaC2J6d5v8JQHbLnI+8F3c7gV6bw83G4JLIJfYSvSZTgDbZqybNGEEVk2b2DEjJsnB2 nxIQ==; 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=percona.com; s=google; t=1773093332; x=1773698132; darn=lists.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=Kwe6UtWyx2OVuW6T083mQimPhpVfcse2SiONat5M5AA=; b=G3tZ5PyJPOcqWlKcJPECuTgCfZuGvAQk7JlAc7P9zs0saL3W21Anqs783ST+ijeEpF Pe3SHPj3xUy9WJfsAHC6tHjMeIU0a5Mw7udxBGkBxRh3+epWCNCg4s6kn1G8gZ2Ju4Ay FJxcSNXQ511QV9z5U7OcaGm3KKMJ/WbQaC570= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773093332; x=1773698132; 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=Kwe6UtWyx2OVuW6T083mQimPhpVfcse2SiONat5M5AA=; b=gKmR4g0BVpES4dpdUG9nOd4568kS5Yx2RAmHsgPfA2qC6xgxnENRGSrWE3CcCY4zG/ HsfDDqR7eXQQnkzeWvNjNy+LFpONccfXJquYnvL+OVfeF77jtgsO+GaeZrnP+bK1dmY4 TdjCkFkrnGMXQOsrTTtvcVQGHv5Kz0lRZvvymH7RlSBIOMklcgy3ol8O5hMAYO18BXeS cJ6vXCzpC4ozceCzJixeIiQaCTzsO3f6klwaaXmAB344E4dsRKTaDd1p2R9XP5l4q5jM ChjWLsEBMC76YWqCh12fBtecOCth10gjMQEeyM0XpONxOro01f9kt0dNBotC2wRqz6Z8 Qu3w== X-Gm-Message-State: AOJu0Yyjwn8we5PF1DnYq0zOIXElA4n29S8xHrmZzq64BOTJhFkKg6TG R9mkU7B+kD7VNDhQB75Xw0kOm1aidTeEY0epvkeKexJbi5U35+01NV9bZOSSJH/pAF54lK+3PwE dctqDH3agoyak62Hb1sC6uK1DQUlwnSoixcGKM+DvcOqZihWxGQdI4esY2Hnmcpu3J/YTMrqNNZ GrxG3n1ulwGCmLTD6tpqmzxTVpNXTGGSXWk1bi7jzCThT2SsierCuXbrfnFQUPleXiSyQ+aj8vU hEQIewtzzbTKXRXu4uvk1x3DTBQcuMKVmgTj0gw7XEjmwDHcFhPOGEfWI29ARo1BTY= X-Gm-Gg: ATEYQzxv6NkCF0t4Xedcs9XSfJzLLs2UovHmH8wPfGJ02ZqX3UTEd1p9obTG8gkZyPm 8cUlY5LMHZmWI0l6eJ6attrL2PizjKoK1H0xay6RlLLyIl8vHYNTu/BMDYtYzFava69hmqYT07b PT7oiaJLSNhN8YEADox2PxRYH0xU0bxHllynW1+gIGHvbk48Z1DXLhK0rcENbDTSbYjXIxDrdsH i5K3brJPSKs+WAvo9UekveZaJzi+i0fdk0hfLbRj6dT4isR7Odm9vdzc0C0PhziKzEfnLyuSHBm qoJ3K4Fto09bySbououT3NB6xRk6tDTYpGOag2GoOAfOfcWYgtj2bkYnZV/9Xz6NV6Wj X-Received: by 2002:a05:690c:23c5:b0:797:d45d:6fee with SMTP id 00721157ae682-798dd7c3fbfmr124671677b3.55.1773093332099; Mon, 09 Mar 2026 14:55:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Zsolt Parragi Date: Mon, 9 Mar 2026 21:55:22 +0000 X-Gm-Features: AaiRm53MLERYcDyM-Zj2aBNKfb8pax_exKZEm5O-YNaGZKJ2It7Xw-MU_iTUcTM Message-ID: Subject: Re: Stack-based tracking of per-node WAL/buffer usage To: Lukas Fittl Cc: PostgreSQL Hackers , Andres Freund , Peter Smith Content-Type: text/plain; charset="UTF-8" X-CLOUD-SEC-AV-Sent: true X-CLOUD-SEC-AV-Info: percona,google_mail,monitor X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello + if (queryDesc->totaltime && estate->es_instrument && !IsParallelWorker()) + { + ExecFinalizeNodeInstrumentation(queryDesc->planstate); + + ExecFinalizeTriggerInstrumentation(estate); + } + if (queryDesc->totaltime) - InstrStop(queryDesc->totaltime); + queryDesc->totaltime = InstrQueryStopFinalize(queryDesc->totaltime); In ExecFinalizeNodeInstrumentation InstrFinalizeNode pfrees the original instrumentation, but doesn't remove it from the unfinalized_children list. In normal execution in InstrQueryStopFinalize ResourceOwnerForgetInstrumentation handles this, but what about the error path, if something happens between the two? Won't we end up in ResOwnerReleaseInstrumentation and do use after free reads and then a double free on the now invalid pointer? + if (myState->es->timing || myState->es->buffers) + instr = InstrQueryStopFinalize(instr); + Is it okay to leak 1 instrumentation copy per tuple in the query context? This freshly palloced object will be out of scope a few lines after this. @@ -128,8 +130,22 @@ IndexNext(IndexScanState *node) IndexNextWithReorder doesn't need the same handling? + if (scandesc->xs_heap_continue) + elog(ERROR, "non-MVCC snapshots are not supported in index-only scans"); Shouldn't this say index scans? (there's another preexisting indexonylscan mention in this file, but that also seems wrong) +#if HAVE_INSTR_STACK + usage = &instr_top.bufusage; +#else + usage = &pgBufferUsage; +#endif I don't see pgBufferUsage anywhere else in the current code, it was probably removed between rebases? + char *prefix = title ? psprintf("%s ", title) : pstrdup(""); + + ExplainPropertyInteger(psprintf("%sShared Hit Blocks", prefix), NULL, usage->shared_blks_hit, es); (And many similar ExplainPropery after this) title is NULL most of the time, and this results in 16 allocations for that common case - isn't there a better solution like using ExplainOpenGroup or something? + * Callers must ensure that no intermediate stack entries are skipped, to + * handle aborts correctly. If you're thinking of calling this in a PG_FINALLY + * block, instead call InstrPopAndFinalizeStack which can skip intermediate + * stack entries, or instead use InstrStart/InstrStop. InstrPopAndFinalizeStack doesn't exists in the latest patch version