Re: Forbid to DROP temp tables of other sessions

From: Steven Niu <niushiji(at)gmail(dot)com>
To: Daniil Davydov <3danissimo(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "Andrey M(dot) Borodin" <x4mmm(at)yandex-team(dot)ru>, Andres Freund <andres(at)anarazel(dot)de>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Rafia Sabih <rafia(dot)pghackers(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Forbid to DROP temp tables of other sessions
Date: 2025-03-17 13:28:50
Message-ID: f77435e7-e7ea-46c3-b425-5c17075c9a3e@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

在 2025/3/17 18:56, Daniil Davydov 写道:
> Hi,
>
> On Mon, Mar 17, 2025 at 5:33 PM Steven Niu <niushiji(at)gmail(dot)com> wrote:
>>
>> I mean RangeVarGetRelidExtended(), you deleted the following code:
>>
>> if (!OidIsValid(myTempNamespace))
>> relId = InvalidOid; /* this probably can't happen? */
>
> Hm, I got it. Let's start with the fact that the comment "this
> probably can't happen?" is incorrect. Even if we don't have a
> temporary namespace in our session, we still can specify "pg_temp_N"
> in the psql query.
> Next, if relation->schemaname is pg_temp, then we firstly call
> LookupExplicitNamespace, where you can find if
> (!OidIsValid(myTempNamespace)) check.
>
> --
> Best regards,
> Daniil Davydov

If the (relation->relpersistence == RELPERSISTENCE_TEMP) can ensure the
myTempNamespace is always valid, then my comment can be ignored.
Otherwise I think the modified RangeVarGetRelidExtended() should keep
check of myTempNamespace, like this:

if (relation->relpersistence == RELPERSISTENCE_TEMP)
{
Oid namespaceId;

if (!OidIsValid(myTempNamespace))
relId = InvalidOid; /* this probably can't happen? */
else
{
if (relation->schemaname)
{
namespaceId = LookupExplicitNamespace(relation->schemaname,
missing_ok);
if (namespaceId != myTempNamespace)
{
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("could not access temporary relations of other
sessions")));
}
}
else
{
namespaceId = myTempNamespace;
Assert(OidIsValid(namespaceId));
}
if (missing_ok && !OidIsValid(namespaceId))
relId = InvalidOid;
else
relId = get_relname_relid(relation->relname, namespaceId);
}
...
...

Thanks,
Steven

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Dmitry Koval 2025-03-17 13:36:56 Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Previous Message Andrei Lepikhov 2025-03-17 13:28:02 Prune partitions by ScalarArrayOpExpr with an array parameter (partkey = ANY($1))