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