Re: Re: proposal: schema variables

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>, Erik Rijkers <er(at)xs4all(dot)nl>, Michael Paquier <michael(at)paquier(dot)xyz>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, DUVAL REMI <REMI(dot)DUVAL(at)cheops(dot)fr>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re: proposal: schema variables
Date: 2025-01-06 07:58:36
Message-ID: CACJufxG7Mc2PK2B7+vkdDxvrsJNN3r+cpzvAFTZZXKnWZOcG6w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-performance

comment out the changes in
src/backend/utils/cache/plancache.c

// /* process session variables */
// if (OidIsValid(parsetree->resultVariable))
// {
// if (acquire)
// LockDatabaseObject(VariableRelationId, parsetree->resultVariable,
// 0, AccessShareLock);
// else
// UnlockDatabaseObject(VariableRelationId,
parsetree->resultVariable,
// 0, AccessShareLock);
// }

// else if (IsA(node, Param))
// {
// Param *p = (Param *) node;
// if (p->paramkind == PARAM_VARIABLE)
// {
// if (acquire)
// LockDatabaseObject(VariableRelationId, p->paramvarid,
// 0, AccessShareLock);
// else
// UnlockDatabaseObject(VariableRelationId, p->paramvarid,
// 0, AccessShareLock);
// }
// }
the regress tests are still successful, that means these code changes
don't have related tests.

SetSessionVariable(Oid varid, Datum value, bool isNull)
{
create_sessionvars_hashtables();
svar = (SVariable) hash_search(sessionvars, &varid, HASH_ENTER, &found);
if (!found)
setup_session_variable(svar, varid);
/* if this fails, it won't change the stored value */
set_session_variable(svar, value, isNull);
}
after set_session_variable,
we want to make sure that svar->is_valid is true,
svar->value = value and svar->isnull= isNull.
Based on this, I've simplified the function set_session_variable,
refer v1-0001-minor-refactoring-set_session_variable.no-cfbot

we use PlannerGlobal
{
Oid basenodeSessionVarid;
Bitmapset *checkSelectPermVarids;
}
to solve the self-assigned corner case SELECT privilege.
(let v1.a =v1.a; in this case, we need have SELECT priv for v1.a
but let v1.a = 1, we don't need SELECT priv for v1.a).

i found out these two field value(information) most case is the same
as PlannerGlobal.sessionVariables;
I came up with another solution, introduce a bool (Query.is_Variable_assigned),
and get rid of PlannerGlobal.basenodeSessionVarid,
PlannerGlobal.checkSelectPermVarids.
not sure it make sense to you, refer
v1-0002-refactoring-LET-statement-self-assign-privileg.no-cfbot

Attachment Content-Type Size
v1-0001-minor-refactoring-set_session_variable.no-cfbot application/octet-stream 2.1 KB
v1-0002-refactoring-LET-statement-self-assign-privileg.no-cfbot application/octet-stream 4.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiro Ikeda 2025-01-06 08:18:39 Re: Doc: fix the rewrite condition when executing ALTER TABLE ADD COLUMN
Previous Message Tatsuo Ishii 2025-01-06 07:31:07 Refactor WinGetFuncArgInFrame

Browse pgsql-performance by date

  From Date Subject
Next Message Pavel Stehule 2025-01-06 08:39:39 Re: Re: proposal: schema variables
Previous Message jian he 2025-01-05 16:10:37 Re: Re: proposal: schema variables