Skip to content

Commit 84ee727

Browse files
[OSS-ONLY] [BABEL] Add PLtsql node serialization support for ANTLR parse tree caching (#750)
Description BABEL-6037: Add pg_strtok_init() for extension-side node deserialization. The Babelfish extension implements cross-session ANTLR parse tree caching for T-SQL stored procedures. Serialized parse trees are stored in sys.babelfish_function_ext and deserialized on first execution in new sessions to skip redundant ANTLR parsing. The extension handles all PLtsql node serialization and deserialization on its own side (under babelfish_extensions/contrib/babelfishpg_tsql/src/pltsql_serialize, specifically pltsql_nodeio.c), replicating the necessary internal macros from outfuncs.c and readfuncs.c (WRITE_*/READ_* macros in pltsql_serialize_macros.h) and PR serialization/deserialization (NodeToString()/StringToNode()) functions (from outfuncs.c,read.c) delegating to PG's public APIs (outNode(), nodeRead(), parseNodeString()) for standard PG types. (refer: postgresql_modified_for_babelfish/src/backend/nodes/*) For deserialization, the extension needs to point pg_strtok at its own input string before calling its reader. Since pg_strtok_ptr is static in read.c, this PR adds a minimal public setter function. Changes pg_strtok_init (read.c, readfuncs.h) read.c: Add pg_strtok_init(const char *str) — sets the static pg_strtok_ptr so extensions can initialize the tokenizer for their own deserialization readfuncs.h: Add extern declaration Issues Resolved: BABEL-6037 (cherry picked from commit 3a9910d) Signed-off-by: Manisha Deshpande <mmdeshp@amazon.com>
1 parent 70ec67e commit 84ee727

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/backend/nodes/read.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@
3131
/* Static state for pg_strtok */
3232
static const char *pg_strtok_ptr = NULL;
3333

34+
/*
35+
* pg_strtok_init - set the input string for pg_strtok.
36+
*
37+
* Allows extensions to initialize the tokenizer state for their own
38+
* deserialization without needing access to the static pg_strtok_ptr.
39+
*/
40+
void
41+
pg_strtok_init(const char *str)
42+
{
43+
pg_strtok_ptr = str;
44+
}
45+
3446
/* State flag that determines how readfuncs.c should treat location fields */
3547
#ifdef DEBUG_NODE_TESTS_ENABLED
3648
bool restore_location_fields = false;

src/include/nodes/readfuncs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern PGDLLIMPORT bool restore_location_fields;
2727
* prototypes for functions in read.c (the lisp token parser)
2828
*/
2929
extern const char *pg_strtok(int *length);
30+
extern void pg_strtok_init(const char *str);
3031
extern char *debackslash(const char *token, int length);
3132
extern void *nodeRead(const char *token, int tok_len);
3233

0 commit comments

Comments
 (0)