Skip to content

Commit e2cda3c

Browse files
author
Amit Kapila
committed
Fix use of relcache TriggerDesc field introduced by commit 05c8482.
The commit added code which used a relcache TriggerDesc field across another cache access, which it shouldn't because the relcache doesn't guarantee it won't get moved. Diagnosed-by: Tom Lane Author: Greg Nancarrow Reviewed-by: Hou Zhijie, Amit Kapila Discussion: https://postgr.es/m/2309260.1615485644@sss.pgh.pa.us
1 parent 57dcc2e commit e2cda3c

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/backend/optimizer/util/clauses.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ static bool target_rel_max_parallel_hazard(max_parallel_hazard_context *context)
114114
static bool target_rel_max_parallel_hazard_recurse(Relation relation,
115115
CmdType command_type,
116116
max_parallel_hazard_context *context);
117-
static bool target_rel_trigger_max_parallel_hazard(TriggerDesc *trigdesc,
117+
static bool target_rel_trigger_max_parallel_hazard(Relation rel,
118118
max_parallel_hazard_context *context);
119119
static bool target_rel_index_max_parallel_hazard(Relation rel,
120120
max_parallel_hazard_context *context);
@@ -926,7 +926,7 @@ target_rel_max_parallel_hazard_recurse(Relation rel,
926926
/*
927927
* If any triggers exist, check that they are parallel-safe.
928928
*/
929-
if (target_rel_trigger_max_parallel_hazard(rel->trigdesc, context))
929+
if (target_rel_trigger_max_parallel_hazard(rel, context))
930930
return true;
931931

932932
/*
@@ -952,23 +952,29 @@ target_rel_max_parallel_hazard_recurse(Relation rel,
952952
/*
953953
* target_rel_trigger_max_parallel_hazard
954954
*
955-
* Finds the maximum parallel-mode hazard level for the specified trigger data.
955+
* Finds the maximum parallel-mode hazard level for the specified relation's
956+
* trigger data.
956957
*/
957958
static bool
958-
target_rel_trigger_max_parallel_hazard(TriggerDesc *trigdesc,
959+
target_rel_trigger_max_parallel_hazard(Relation rel,
959960
max_parallel_hazard_context *context)
960961
{
961962
int i;
962963

963-
if (trigdesc == NULL)
964+
if (rel->trigdesc == NULL)
964965
return false;
965966

966-
for (i = 0; i < trigdesc->numtriggers; i++)
967+
/*
968+
* Care is needed here to avoid using the same relcache TriggerDesc field
969+
* across other cache accesses, because relcache doesn't guarantee that it
970+
* won't move.
971+
*/
972+
for (i = 0; i < rel->trigdesc->numtriggers; i++)
967973
{
968974
int trigtype;
969-
Trigger *trigger = &trigdesc->triggers[i];
975+
Oid tgfoid = rel->trigdesc->triggers[i].tgfoid;
970976

971-
if (max_parallel_hazard_test(func_parallel(trigger->tgfoid), context))
977+
if (max_parallel_hazard_test(func_parallel(tgfoid), context))
972978
return true;
973979

974980
/*
@@ -977,7 +983,7 @@ target_rel_trigger_max_parallel_hazard(TriggerDesc *trigdesc,
977983
* on insert/update and this isn't supported in a parallel worker (but
978984
* is safe in the parallel leader).
979985
*/
980-
trigtype = RI_FKey_trigger_type(trigger->tgfoid);
986+
trigtype = RI_FKey_trigger_type(tgfoid);
981987
if (trigtype == RI_TRIGGER_FK)
982988
{
983989
if (max_parallel_hazard_test(PROPARALLEL_RESTRICTED, context))

0 commit comments

Comments
 (0)