Skip to content

Commit 9926f85

Browse files
committed
Cache NO ACTION foreign keys separately from RESTRICT foreign keys
Now that we generate different SQL for temporal NO ACTION vs RESTRICT foreign keys, we should cache their query plans with different keys. Since the key also includes the constraint oid, this shouldn't be necessary, but we have been seeing build farm failures that suggest we might be sometimes using a cached NO ACTION plan to implement a RESTRICT constraint. Author: Paul A. Jungwirth <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/CA+renyUApHgSZF9-nd-a0+OPGharLQLO=mDHcY4_qQ0+noCUVg@mail.gmail.com
1 parent a925862 commit 9926f85

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/backend/utils/adt/ri_triggers.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,13 @@
7474
/* these queries are executed against the FK (referencing) table: */
7575
#define RI_PLAN_CASCADE_ONDELETE 3
7676
#define RI_PLAN_CASCADE_ONUPDATE 4
77+
#define RI_PLAN_NO_ACTION 5
7778
/* For RESTRICT, the same plan can be used for both ON DELETE and ON UPDATE triggers. */
78-
#define RI_PLAN_RESTRICT 5
79-
#define RI_PLAN_SETNULL_ONDELETE 6
80-
#define RI_PLAN_SETNULL_ONUPDATE 7
81-
#define RI_PLAN_SETDEFAULT_ONDELETE 8
82-
#define RI_PLAN_SETDEFAULT_ONUPDATE 9
79+
#define RI_PLAN_RESTRICT 6
80+
#define RI_PLAN_SETNULL_ONDELETE 7
81+
#define RI_PLAN_SETNULL_ONUPDATE 8
82+
#define RI_PLAN_SETDEFAULT_ONDELETE 9
83+
#define RI_PLAN_SETDEFAULT_ONUPDATE 10
8384

8485
#define MAX_QUOTED_NAME_LEN (NAMEDATALEN*2+3)
8586
#define MAX_QUOTED_REL_NAME_LEN (MAX_QUOTED_NAME_LEN*2)
@@ -752,7 +753,7 @@ ri_restrict(TriggerData *trigdata, bool is_no_action)
752753
* Fetch or prepare a saved plan for the restrict lookup (it's the same
753754
* query for delete and update cases)
754755
*/
755-
ri_BuildQueryKey(&qkey, riinfo, RI_PLAN_RESTRICT);
756+
ri_BuildQueryKey(&qkey, riinfo, is_no_action ? RI_PLAN_NO_ACTION : RI_PLAN_RESTRICT);
756757

757758
if ((qplan = ri_FetchPreparedPlan(&qkey)) == NULL)
758759
{

0 commit comments

Comments
 (0)