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 1rOKt6-003Kll-Ay for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Jan 2024 17:00:08 +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 1rOKt5-003jUe-Ef for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Jan 2024 17:00:07 +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.94.2) (envelope-from ) id 1rOKt5-003jUW-6j for pgsql-bugs@lists.postgresql.org; Fri, 12 Jan 2024 17:00:07 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rOKt2-001Dfx-Um for pgsql-bugs@lists.postgresql.org; Fri, 12 Jan 2024 17:00:06 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-50ea9e189ebso7501193e87.3 for ; Fri, 12 Jan 2024 09:00:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705078804; x=1705683604; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=+z1fTeR8BsI2TyYNN1gXLKRTZnwzXHpjm7clvvb1M7A=; b=W3Az+OgV/WWsc8I5IbIu1SoVfnvhjr9Q+4pkFerAZZIsbdCzeHGdmVVPoY1l5ZLj3G 6zsc0NKMJp+tWBNkX7IEd3Ne9Z1+u3YD5nQOc/YF9GFC+mqQ0DrBEN7vdjlorvtk5v7B o54TuIuyuMDb6tJPwazsyDJO0xNFEl2TWlgKrwitOI/L/cAWZzsAVIais8WV1MyDhlMF i/82/Y+rIs+1vKZLVSphZqrX+DYnpMdAv3kYZVR7xnwiXd84XoussihYpcyg87oIZ/Fa bxNJQ4rOpDf+LQ7yO9WD6ZEkMV7y4wi8yUJj5hRFr7ttzPof0wTQnShxIBjkzpnfYKtH vciQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705078804; x=1705683604; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+z1fTeR8BsI2TyYNN1gXLKRTZnwzXHpjm7clvvb1M7A=; b=Gr+0Z+PguK95RR+K/bW2hn8FXE69yESTT6QoUWcNweN+3EePR56BzoC+LQ87It+6pg S9ZF6Vg74Ve2fM3iqyTPHaRP9teBDl+8hJYuuyiZ6mqg2Yk+VwXXDFnBAfBAQB24ou79 qaiJOVCYMJ7igArskhuEHm0fYIcbY+t1teYxHihVJOY15rWLTQiWsR+7ZCYPpn7O0oQw F0qkiOHVkFyNBnL7Z4pImo+5ATU464YCPeURqoUiHWwHPTJcxWY4BXhhlQfI2u654z8U 7viHu9rjoGs193saYmZzWHoWEY6ICBE0zdn4Y3hAXR6sSjSP30r/RFyBj2bQhXByo7YO QDcw== X-Gm-Message-State: AOJu0YxanR+MCbNyMJIPLnUVHi6+PR05M3YQkMaUBkJ1AAftr6ExmASg jEcr0/ST4DJFWOq175Sdj6A= X-Google-Smtp-Source: AGHT+IEKLO+gxaGnpQkhRupDwX/tqj6jrUYwFUOdXmKq03z0/VfKs7Zg2EIZryfjOa5iDh0H7F+eoA== X-Received: by 2002:a05:6512:1055:b0:50e:9ba0:5e20 with SMTP id c21-20020a056512105500b0050e9ba05e20mr993251lfb.99.1705078803509; Fri, 12 Jan 2024 09:00:03 -0800 (PST) Received: from [1.0.0.7] ([91.185.77.50]) by smtp.gmail.com with ESMTPSA id q24-20020ac246f8000000b0050ecce84e26sm541981lfo.158.2024.01.12.09.00.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Jan 2024 09:00:02 -0800 (PST) Message-ID: <17124cd9-6515-2076-6eac-40d44388f833@gmail.com> Date: Fri, 12 Jan 2024 20:00:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: BUG #17798: Incorrect memory access occurs when using BEFORE ROW UPDATE trigger Content-Language: en-US To: Robert Haas Cc: Tom Lane , pgsql-bugs@lists.postgresql.org, Richard Guo , Andres Freund , Peter Geoghegan References: <17798-0907404928dcf0dd@postgresql.org> <87fe6c28-80b2-f709-a8db-d105e5240e39@gmail.com> <1849610.1682807087@sss.pgh.pa.us> <494cd7c4-c109-6886-c0e3-138a95e7e38b@gmail.com> <74335d44-819d-60e0-859a-efe74d9c84c2@gmail.com> <325298.1705009396@sss.pgh.pa.us> <94ca869c-472b-f1cf-3d7c-aa8530f5475d@gmail.com> From: Alexander Lakhin In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 12.01.2024 17:56, Robert Haas wrote: > On Fri, Jan 12, 2024 at 8:00 AM Alexander Lakhin wrote: >> I had decided to move that step out of "if (epqslot_candidate != NULL)" >> in v3 to play safe when removing ExecMaterializeSlot(newslot) brought by >> 75e03eabe (more details upthread [1]). I thought that if that commit stated >> that the slot needs materialization (it was time before 86dc90056, which >> raised the current issue), then the materialization must be preserved. >> (The same commit can be found in zheap repository [2], but I found no other >> explanation of it's purpose...) >> Though looking at the current core code, I'm inclined to perform >> ExecMaterializeSlot() only when we have epqslot_candidate, if we can afford >> not to bother about that zheap-specific or similar scenario... > I don't understand why it's ever safe to skip ExecMaterializeSlot > here. IIUC, if we have no EPQ slot, newslot is still not materialized > and thus dependent on oldslot ... and we're about to > ExecFetchSlotHeapTuple on oldslot. To my understanding, when we have no epqslot_candidate, it means that newslot came from ExecBRUpdateTriggers's callers and it can't be dependent on an internal oldslot's buffer. For example, ExecModifyTable() does the following:             slot = ExecGetUpdateNewTuple(resultRelInfo, context.planSlot,                                             oldSlot);             context.relaction = NULL;             /* Now apply the update. */             slot = ExecUpdate(&context, resultRelInfo, tupleid, oldtuple,                                 slot, node->canSetTag); Thus, newslot (aka slot here) depends on oldSlot inside ExecModifyTable(), but not on oldslot inside ExecBRUpdateTriggers(), so ExecFetchSlotHeapTuple(oldslot,...) can't affect it. Though then we still have the question regarding zheap open -- can some external code introduce new implicit dependencies? Best regards, Alexander