@@ -114,7 +114,7 @@ static bool target_rel_max_parallel_hazard(max_parallel_hazard_context *context)
114114static 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 );
119119static 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 */
957958static 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