From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Make stringToNode() infrastructure thread-safe
Date: Mon, 24 Aug 2026 03:18:06 +0000
Message-ID: <E1wyLCH-00000001qcJ-2iGY@gemulon.postgresql.org> (raw)
Make stringToNode() infrastructure thread-safe
While stringToNode() was technically reentrant-safe, this was only for
single-threaded workloads: the string decoded was stored in a global
variable. This may be unsafe depending on the execution model, and
definitely unsafe in multi-threaded environments.
This patch moves the global variables into a struct (ReadNodeContext),
whose pointer is passed around on the stack. Support functions for node
read, extensible nodes (note: these have never been tested, should be
tested) and pg_strtok() are updated to handle the context data across
the call stack.
Code simplifications are mostly in stringToNodeInternal(), that can rely
on the context structure rather than a save-and-reassign logic based on
the global variables previously available.
Author: Matthias van de Meent <boekewurm+postgres@gmail.com>
Reviewed-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Yuhang Qiu <iamqyh@gmail.com>
Discussion: https://postgr.es/m/CAEze2WjsGnOM4MB+n1LLdhhUg6r=hwWZRv+-heDE4UtzRdgjyg@mail.gmail.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/9673a0aa92f4fd75c564e2c8e14d71500a7b55ae
Modified Files
--------------
src/backend/nodes/gen_node_support.pl | 8 +-
src/backend/nodes/read.c | 76 +++++------------
src/backend/nodes/readfuncs.c | 152 +++++++++++++++++-----------------
src/include/nodes/extensible.h | 6 +-
src/include/nodes/readfuncs.h | 30 ++++---
src/tools/pgindent/typedefs.list | 1 +
6 files changed, 124 insertions(+), 149 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-committers@postgresql.org
Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Make stringToNode() infrastructure thread-safe
In-Reply-To: <E1wyLCH-00000001qcJ-2iGY@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox