Skip to content

Commit 63d8190

Browse files
svenklemmtimescale-automation
authored andcommitted
Fix ExplainHook breaking call chain
Hooks in postgres are supposed to be chained and call the previous hook in your own added hooks. Not calling previous hook will prevent other extensions from having working hooks. (cherry picked from commit 55fec68)
1 parent 575d6db commit 63d8190

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

.unreleased/pr_7694

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #7694 Fix ExplainHook breaking call chain

tsl/src/hypercore/arrow_cache_explain.c

+16-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
bool decompress_cache_print = false;
1818
struct DecompressCacheStats decompress_cache_stats;
1919
static ExplainOneQuery_hook_type prev_ExplainOneQuery_hook = NULL;
20+
static bool ExplainOneQuery_hook_initialized = false;
2021

2122
#if PG17_LT
2223
/*
@@ -72,7 +73,11 @@ static void
7273
explain_decompression(Query *query, int cursorOptions, IntoClause *into, ExplainState *es,
7374
const char *queryString, ParamListInfo params, QueryEnvironment *queryEnv)
7475
{
75-
standard_ExplainOneQuery(query, cursorOptions, into, es, queryString, params, queryEnv);
76+
if (prev_ExplainOneQuery_hook)
77+
prev_ExplainOneQuery_hook(query, cursorOptions, into, es, queryString, params, queryEnv);
78+
else
79+
standard_ExplainOneQuery(query, cursorOptions, into, es, queryString, params, queryEnv);
80+
7681
if (decompress_cache_print)
7782
{
7883
const bool has_decompress_data = decompress_cache_stats.decompressions > 0 ||
@@ -130,6 +135,14 @@ tsl_process_explain_def(DefElem *opt)
130135
void
131136
_arrow_cache_explain_init(void)
132137
{
133-
prev_ExplainOneQuery_hook = ExplainOneQuery_hook;
134-
ExplainOneQuery_hook = explain_decompression;
138+
/*
139+
* TSL init might be reexecuted so we need to make
140+
* sure to not initialize hook multiple times
141+
*/
142+
if (!ExplainOneQuery_hook_initialized)
143+
{
144+
ExplainOneQuery_hook_initialized = true;
145+
prev_ExplainOneQuery_hook = ExplainOneQuery_hook;
146+
ExplainOneQuery_hook = explain_decompression;
147+
}
135148
}

0 commit comments

Comments
 (0)