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 1wArKa-000TDn-1c for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Apr 2026 15:30:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wArKY-006RNj-2B for pgsql-hackers@arkaria.postgresql.org; Thu, 09 Apr 2026 15:30:07 +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.96) (envelope-from <3danissimo@gmail.com>) id 1wArKY-006RNM-0q for pgsql-hackers@lists.postgresql.org; Thu, 09 Apr 2026 15:30:07 +0000 Received: from mail-yx1-xb12f.google.com ([2607:f8b0:4864:20::b12f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from <3danissimo@gmail.com>) id 1wArKX-00000000BV9-0aTa for pgsql-hackers@postgresql.org; Thu, 09 Apr 2026 15:30:06 +0000 Received: by mail-yx1-xb12f.google.com with SMTP id 956f58d0204a3-64e87a81639so1055069d50.0 for ; Thu, 09 Apr 2026 08:30:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775748605; cv=none; d=google.com; s=arc-20240605; b=Kzxn2Giu4fsRN7LCTeeQ2MXT8LOkvbShTatDIFIGI8hBra9km2bJLlG6xdXI7jI5Yf NDuHatjTTbqqks0ehXfvFR6T5ovEZoqLugmfUiauKXyhd6kfI5g1O+TsXjkesoMxnO2i jcijJkMAo0i2vXOd1bDPYbVndswKI0y7Yprh+ruH1iBpafb3nnBkH0MqtR962nHTQoDQ DVo20Sz/C49Y6Y8Dtdqz3nrRISAPfPVP2BGvBCT5aiF4KL01JN7KotkNNntNBh6b4a1h /i7p6c0YXQxht8QDRzQ3p4in64QgLhEQ5emCCfwItvlmnODuveXOIH95B4Vis7n6NEDp hUvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=m3hkc8h/YIIcJA6vy60z8f1oYQhJW+DXpxO0jC85X9A=; fh=wBxEah12/J+LEH/7ZaFnveuoHBibkj/r2nOBySi8eiU=; b=ItFp6dGbcsvIRUXH869OO85Jf5EythCNYSLsdpIdNtry0STD+0P7ePGlHLjKB/Nzwn tKxaHTJhr9iZdiEY3GIrSfkannfY6u0xJ+WOZ5yluPHoQsQEvGr3+rEeQKLjwOJ860uY ckooUu5NSYDX3CGwaZi1VmRoPncgSfPOM56UpPkkb9VEMHybWYMYh0+JcMTKU9PpeNYm KPlKcWqEEbXDWoYvhsKt65cH1ehjnQTskkt3C5Bk6oisEaCO/NJlx6jM7CkwgVrzcZRz N4eMZncV6NatwaESXGWQ2iCKyRCuDXRvk9fXcUgwQakkI+4amcQlPD3ZXxKzif3FGBDr 67Gg==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775748605; x=1776353405; 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=m3hkc8h/YIIcJA6vy60z8f1oYQhJW+DXpxO0jC85X9A=; b=SYNUNroHNfDgrbtKmbYbYEDzslnEvFpD5wzzcWs4HrjTjjJgSwj39L6HWWk4uHr9vR 1FPdJyPEFoVJxIPQLmO3EB2u7BR/aHf+VynXkC8zYi+ryOjOfRKBc+Q32V6gKEmM/OK2 AyyJAQa5s6s/+2dJR1H5RJ6cGaRUXLl0ifT8TYvEa+8WiAPnNUTBR0ACZTKrTLJa0H/S j4sxlQVYGMe6zAeO4jBoJo0pbOqW0BfspQ1ChcWCcNcuql8JiEK6OQQ/km5nLTxZKTZd R4WBuNqbY+z/U2iRhN+WJHV7dzPGWBd7v7Av0CrNQQXaybm+u/+8z04TZ1HnYvwbzr9q mLTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775748605; x=1776353405; h=content-transfer-encoding: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=m3hkc8h/YIIcJA6vy60z8f1oYQhJW+DXpxO0jC85X9A=; b=n1ze3/MeoyoBMNGzOYfX7I7jGI2KyDpojC2DRxcrS7Eybjhs41Mk/DZWyZB8mAMw10 67JPfDZGa932xcGBakSjZNJy6i2sBAZG2t6sk5D8zkWz2hgTvDogu6/1tv/PNsfaHm76 NiZvfIGuRso2kE/KZVQyiq/4zJHmaMATJgT1t8awlXTaJ3FuOSk3bYE3meCTuNjttaeF xH8u+x6M2StQdzxJb47OJzt9Y1o2+XZW7Gzayj+6TKXvcdATwxyjXKQN7fzz47Zxnesz 74dJ1T8uDMjZeSZab2SxArzAXT4zAT6B9FLF2eZdL8roNge1hbGh6ZVic6Px/AcAT8v5 mH3g== X-Forwarded-Encrypted: i=1; AJvYcCX1WtzH9g7RYF1kvI3t1KgR2RgiFmcY7yBJxf4iuEuTMWQ8UwnWSttDok1iuY6WVbRj41/cicsN6cKSKuj0@postgresql.org X-Gm-Message-State: AOJu0YwnwzaScxhOt2o4vCdQ/yZlKyKjvVunKARghs+BwzNaWSIp3q2s qFkvsypB1FFyPRayftrhUDoT59kPxRjSuelYysvy2ydaVzts5/rSgGVoGPZm+6pIf3rP/MjU6sX OYgGSRrGSw3sRjFaQqnaHpRqNUe2vgcg= X-Gm-Gg: AeBDiesiHJN8Z3sk8OXl0W9z7AZTbn+eRV4C92+KODNV01bnOElLXexKj6Y9XBCo/k2 g5mgW2X+nJbPCZnz7LvBmhQ5NdjZG4ENYry1V/ij1fh+ToJe6MYJVJ0Jvq0fSdCkquMdK40uJOX 2ycY0oztqSOUMEMOxWVBnAaNPiZahUf20wH06IsaYazkTZdGnse2S+Jj7bohFgxtQSGoBJN5V8C hGO2rG9CQi6Uh1FNrT8WuUiCACVYeT5HjEOKqj68G4Kh+iPLkUZtWKQcKYu5mifJxTexZECnKGt 2xbg+PvmlQ8BIOrA784= X-Received: by 2002:a05:690e:4812:b0:64a:d20a:2e98 with SMTP id 956f58d0204a3-650486dd1e4mr18648652d50.16.1775748604497; Thu, 09 Apr 2026 08:30:04 -0700 (PDT) MIME-Version: 1.0 References: <751a6cb8-cac8-46c4-8c64-9e23f663e926@uni-muenster.de> <1a32fc83-df78-4774-97dc-2bb06dbb16e9@uni-muenster.de> <3529398.1774273446@sss.pgh.pa.us> <4075754.1774378690@sss.pgh.pa.us> <67637cf8-8cbf-4f86-8775-52aa0329972d@uni-muenster.de> In-Reply-To: From: Daniil Davydov <3danissimo@gmail.com> Date: Thu, 9 Apr 2026 22:29:52 +0700 X-Gm-Features: AQROBzBXVtO72Vk9IpK_xai6QEwBLMFVvxyVi40tf149f5QcafoB7WDrt3DX3EE Message-ID: Subject: Re: Fix bug with accessing to temporary tables of other sessions To: Jim Jones Cc: Soumya S Murali , Tom Lane , Stepan Neretin , PostgreSQL Hackers 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 Hi, On Thu, Apr 9, 2026 at 9:35=E2=80=AFPM Jim Jones wrote: > > On 09/04/2026 13:46, Daniil Davydov wrote: > > 1) Right now, read stream seems like an appropriate place for this rest= riction. > > But actually the StartReadBuffers is not "binded" to the read stream lo= gic. I > > mean that if someone calls it bypassing the "read_stream_begin_relation= " > > function (it is OK to do so), then our restriction will be violated aga= in. > > I think that it will be more reliable to add the restriction directly t= o the > > StartReadBuffers. Also, we can add an assertion ("relation is not other= temp > > table") to the PinBufferForBlock. What do you think?> 2) If we decide t= o leave restriction in the "read_stream_begin_relation" > > function, I would suggest adding a "rel !=3D NULL" check here (read_str= eam.c): > > + if (RELATION_IS_OTHER_TEMP(rel)) > > + ereport(ERROR, > > + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), > > + errmsg("cannot access temporary relations of other > > sessions"))); > > 3) The "rel !=3D NULL" checks may use the "RelationIsValid" macro, whic= h seems > > more pretty to me. > > > Mm, not so sure... > AFAICT moving the check to StartReadBuffersImpl would require an extra > NULL guard that isn't needed in read_stream_begin_relation, as the > callers already pass valid Relations. So, rel !=3D NULL is not needed. Hm. I see that read_stream_begin_relation immediately calls read_stream_begin_impl, where we have a "rel !=3D NULL" check (read_stream.= c:787). Anyway, I think that we shouldn't rely on the fact that a given Relation wi= ll always be valid. Please, correct me if I am wrong. I see that you don't really like the idea of moving this check. But since a vectored variant of ReadBuffer() may be used by anyone, don't we need to ta= ke it into account? > Also, wouldn't it potentially make this check multiple times in a table > scan? Yep, it will. It is exactly the same logic as for ReadBuffer_common, PrefetchBuffer and ReadBufferExtended (i.e. checking this constraint before each buffer read). I don't see anything wrong with this approach. More precisely, it would be good to avoid multiple checks, but I don't see a way= to do that. -- Best regards, Daniil Davydov