Re: Schema variables - new implementation for Postgres 15

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Julien Rouhaud <rjuju123(at)gmail(dot)com>
Cc: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Joel Jacobson <joel(at)compiler(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>
Subject: Re: Schema variables - new implementation for Postgres 15
Date: 2022-01-26 13:43:54
Message-ID: CAFj8pRDWntu3JUix5-YNrnX0GmAYWyPOjbhxZxbQ_7QZ7x6fDw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> sessionvariable.c:
>
> + * Although session variables are not transactional, we don't
> + * want (and we cannot) to run cleaning immediately (when we
> + * got sinval message). The value of session variables can
> + * be still used or the operation that emits cleaning can be
> + * reverted. Unfortunatelly, this check can be done only in
> + * when transaction is committed (the check against system
> + * catalog requires transaction state).
>
> This was the original idea, but since there's now locking to make all DDL
> safe,
> the metadata should be considered fully transactional and no session should
> still be able to use a concurrently dropped variable. Also, the
> invalidation
> messages are not sent until the transaction is committed. So is that
> approach
> still needed (at least for things outside ON COMMIT DROP / ON TRANSACTION
> END
> RESET
>

I think this is still necessary. The lock protects the variable against
drop from the second session, but not for reverted deletion from the
current session.

This implementation is due Tomas's request for

CREATE VARIABLE xx AS int;
LET xx = 100;
BEGIN;
DROP VARIABLE xx;
ROLLBACK;
SELECT xx; --> 100

and the variable still holds the last value before DROP

Personally, this is a corner case (for me, and I think so for users it is
not too interesting, and important), and this behavior is not necessary -
originally I implemented just the RESET variable in this case. On the other
hand, this is a nice feature, and there is an analogy with TRUNCATE
behavior.

More, I promised, as a second step, implementation of optional
transactional behavior of session variables. And related code is necessary
for it. So I prefer to use related code without change.

Regards

Pavel

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2022-01-26 13:52:03 Re: libpq async duplicate error results
Previous Message Andrei Zubkov 2022-01-26 13:43:04 Re: [PATCH] Tracking statements entry timestamp in pg_stat_statements