Can I assume relation would not be invalid during from ExecutorRun to ExecutorEnd

From: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Can I assume relation would not be invalid during from ExecutorRun to ExecutorEnd
Date: 2021-11-29 07:10:03
Message-ID: CAKU4AWpoTmGpR0o-qfrAxBndGnfCoNVPQYa2vBC_-u=UAhhYWA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

During my recent work, I need some new stuff attached to Relation. Rather
than adding
some new data structures, I added it to Relation directly. Like
relation->balabala. Then
I initialize it during ExecutorRun, like table_tuple_insert.. and
destroy it at ExecutorEnd.

The above solution works based on 2 assumptions at least:
1. During the ExecutorRun & ExecutorEnd, the relcache will never by
invalidated, if not
the old relation->balabala will be lost. I assume this is correct since I
didn't see any places
where we handle such changes in Executor code.
2. We need to consider the ExuecotRun raised error, we need to destroy
the balabala resource
as well. so I added it to the RelationClose function.

So the overall design works like this:

xxx_table_tuple_insert(Relation rel, ...)
{
if (rel->balabala == NULL)
rel->balabala = allocate_bala_resource(rel); // Allocate the
memory xCtx which is under TopTransactionContext.
do_task_with(rel->balabala);
}

at the end of the executor, I run

release_bala_resource(Relation rel)
{
if (rel->balabala == NULL)
return;
do_the_real_task();
MemoryContextDelete(rel->bala->memctx);
rel->balabala = NULL
}

For the failed cases:

RelationClose(..)
{
if (RelationHasReferenceCountZero(relation))
release_bala_resource(relation);
}

Will my suluation work?

--
Best Regards
Andy Fan

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Antonin Houska 2021-11-29 07:37:31 Re: XTS cipher mode for cluster file encryption
Previous Message Bharath Rupireddy 2021-11-29 06:49:00 Re: Synchronizing slots from primary to standby