diff options
| author | Heikki Linnakangas | 2024-03-03 17:37:28 +0000 |
|---|---|---|
| committer | Heikki Linnakangas | 2024-03-03 17:37:28 +0000 |
| commit | ab355e3a88de745607f6dd4c21f0119b5c68f2ad (patch) | |
| tree | 7808e71e8fbee29095708f47f80bb2bea099e52e /src/pl | |
| parent | 30b8d6e4ce1112168ddfe8cdbba76fbefd304b34 (diff) | |
Redefine backend ID to be an index into the proc array
Previously, backend ID was an index into the ProcState array, in the
shared cache invalidation manager (sinvaladt.c). The entry in the
ProcState array was reserved at backend startup by scanning the array
for a free entry, and that was also when the backend got its backend
ID. Things become slightly simpler if we redefine backend ID to be the
index into the PGPROC array, and directly use it also as an index to
the ProcState array. This uses a little more memory, as we reserve a
few extra slots in the ProcState array for aux processes that don't
need them, but the simplicity is worth it.
Aux processes now also have a backend ID. This simplifies the
reservation of BackendStatusArray and ProcSignal slots.
You can now convert a backend ID into an index into the PGPROC array
simply by subtracting 1. We still use 0-based "pgprocnos" in various
places, for indexes into the PGPROC array, but the only difference now
is that backend IDs start at 1 while pgprocnos start at 0. (The next
commmit will get rid of the term "backend ID" altogether and make
everything 0-based.)
There is still a 'backendId' field in PGPROC, now part of 'vxid' which
encapsulates the backend ID and local transaction ID together. It's
needed for prepared xacts. For regular backends, the backendId is
always equal to pgprocno + 1, but for prepared xact PGPROC entries,
it's the ID of the original backend that processed the transaction.
Reviewed-by: Andres Freund, Reid Thompson
Discussion: https://www.postgresql.org/message-id/8171f1aa-496f-46a6-afc3-c46fe7a9b407@iki.fi
Diffstat (limited to 'src/pl')
| -rw-r--r-- | src/pl/plpgsql/src/pl_exec.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/pl/plpgsql/src/pl_exec.c b/src/pl/plpgsql/src/pl_exec.c index 6d1691340c5..ed51694428a 100644 --- a/src/pl/plpgsql/src/pl_exec.c +++ b/src/pl/plpgsql/src/pl_exec.c @@ -2211,7 +2211,7 @@ exec_stmt_call(PLpgSQL_execstate *estate, PLpgSQL_stmt_call *stmt) paramLI = setup_param_list(estate, expr); - before_lxid = MyProc->lxid; + before_lxid = MyProc->vxid.lxid; /* * If we have a procedure-lifespan resowner, use that to hold the refcount @@ -2232,7 +2232,7 @@ exec_stmt_call(PLpgSQL_execstate *estate, PLpgSQL_stmt_call *stmt) elog(ERROR, "SPI_execute_plan_extended failed executing query \"%s\": %s", expr->query, SPI_result_code_string(rc)); - after_lxid = MyProc->lxid; + after_lxid = MyProc->vxid.lxid; if (before_lxid != after_lxid) { @@ -6037,7 +6037,7 @@ exec_eval_simple_expr(PLpgSQL_execstate *estate, int32 *rettypmod) { ExprContext *econtext = estate->eval_econtext; - LocalTransactionId curlxid = MyProc->lxid; + LocalTransactionId curlxid = MyProc->vxid.lxid; ParamListInfo paramLI; void *save_setup_arg; bool need_snapshot; @@ -7943,7 +7943,7 @@ get_cast_hashentry(PLpgSQL_execstate *estate, * functions do; DO blocks have private simple_eval_estates, and private * cast hash tables to go with them.) */ - curlxid = MyProc->lxid; + curlxid = MyProc->vxid.lxid; if (cast_entry->cast_lxid != curlxid || cast_entry->cast_in_use) { oldcontext = MemoryContextSwitchTo(estate->simple_eval_estate->es_query_cxt); @@ -8070,7 +8070,7 @@ exec_simple_check_plan(PLpgSQL_execstate *estate, PLpgSQL_expr *expr) /* Remember that we have the refcount */ expr->expr_simple_plansource = plansource; expr->expr_simple_plan = cplan; - expr->expr_simple_plan_lxid = MyProc->lxid; + expr->expr_simple_plan_lxid = MyProc->vxid.lxid; /* Share the remaining work with the replan code path */ exec_save_simple_expr(expr, cplan); |
