Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZfCSX-0006th-66 for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Sep 2015 19:45:37 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZfCSW-0007sm-Nd for pgsql-hackers@arkaria.postgresql.org; Thu, 24 Sep 2015 19:45:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZfCST-0007r6-Qi for pgsql-hackers@postgresql.org; Thu, 24 Sep 2015 19:45:34 +0000 Received: from tamriel.snowman.net ([2001:4830:167b::11]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZfCSQ-0004NU-6j for pgsql-hackers@postgresql.org; Thu, 24 Sep 2015 19:45:32 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id C51355F799; Thu, 24 Sep 2015 15:45:29 -0400 (EDT) Date: Thu, 24 Sep 2015 15:45:29 -0400 From: Stephen Frost To: Tom Lane Cc: Alvaro Herrera , pgsql-hackers@postgresql.org Subject: Rename withCheckOptions to insertedCheckClauses Message-ID: <20150924194529.GF3685@tamriel.snowman.net> References: <22678.1442348981@sss.pgh.pa.us> <20150915220002.GB3685@tamriel.snowman.net> <20150915221655.GK88970@alvherre.pgsql> <27213.1442356184@sss.pgh.pa.us> <20150915224851.GD3685@tamriel.snowman.net> <28196.1442358966@sss.pgh.pa.us> <20150924194358.GE3685@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="WZJyhX63VJL+5o8l" Content-Disposition: inline In-Reply-To: <20150924194358.GE3685@tamriel.snowman.net> X-Editor: Vim http://www.vim.org/ X-Info: http://www.snowman.net X-Operating-System: Linux/3.13.0-61-generic (x86_64) X-Uptime: 15:44:24 up 51 days, 4:14, 3 users, load average: 0.24, 0.12, 0.09 User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --WZJyhX63VJL+5o8l Content-Type: multipart/mixed; boundary="3ChEjlKQG30qDPT4" Content-Disposition: inline --3ChEjlKQG30qDPT4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline All, and this totally should have gone to -hackers instead, sorry about that. Please ignore the one to -committers, if possible. Tom, all, * Tom Lane (tgl@sss.pgh.pa.us) wrote: > My vote would be to rename and reposition the field in HEAD and 9.5 > and accept the corresponding initdb. We already forced an initdb > since alpha2, so it's basically free as far as testers are concerned, > and keeping 9.5 in sync with HEAD in this area seems like a really > good idea for awhile to come. Alright, attached is an attempt at doing these renames. I went a bit farther since it seemed to make sense to me (at least at the time, I'm wondering a bit about it now), so, please provide any thoughts or feedback you have regarding these changes. Thanks! Stephen --3ChEjlKQG30qDPT4 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="wco-rename.v1.patch" Content-Transfer-Encoding: quoted-printable =46rom 579dcfb80ffb922cabf10590219de221bb12267a Mon Sep 17 00:00:00 2001 =46rom: Stephen Frost Date: Thu, 24 Sep 2015 10:21:42 -0400 Subject: [PATCH] Rename withCheckOptions to insertedCheckClauses CHECK clauses which are generated from the WITH CHECK OPTION being specified on a view or from RLS WITH CHECK policies are always inserted by the rewriter and therefore don't ever need to be persisted out on disk for a given query. This modifies outfuncs to no longer output the rewriter-added nodes for a Query or a ModifyTable, and readfuncs to no longer read them in. Further, rename 'withCheckOptions' in Query and ModifyTable to 'insertedCheckClauses', ExecWithCheckOption to ExecCheckClauses, ri_WithCheckOptions and ri_WithCheckOptionExprs to ri_InsertedCheckClauses and ri_InsertedCheckExprs, respectively, all to make it clear that these are the check clauses which were added by the rewriter, not the actual WITH CHECK OPTION indication for a view (which is stored in reloptions for the view) nor the WITH CHECK expressions for a policy (which are stored in pg_policy). Requires a catversion bump. Per discussion with Tom and Alvaro. Backpatch to 9.5 since we're still in alpha. --- src/backend/executor/execMain.c | 16 +++++------ src/backend/executor/nodeModifyTable.c | 45 +++++++++++++++------------= ---- src/backend/nodes/copyfuncs.c | 4 +-- src/backend/nodes/equalfuncs.c | 2 +- src/backend/nodes/nodeFuncs.c | 4 +-- src/backend/nodes/outfuncs.c | 2 -- src/backend/nodes/readfuncs.c | 21 --------------- src/backend/optimizer/plan/createplan.c | 8 +++--- src/backend/optimizer/plan/planner.c | 42 +++++++++++++++++----------= -- src/backend/optimizer/plan/setrefs.c | 4 +-- src/backend/optimizer/prep/prepsecurity.c | 2 +- src/backend/rewrite/rewriteHandler.c | 37 ++++++++++++------------- src/backend/rewrite/rowsecurity.c | 28 +++++++++---------- src/include/executor/executor.h | 2 +- src/include/nodes/execnodes.h | 8 +++--- src/include/nodes/parsenodes.h | 8 ++++-- src/include/nodes/plannodes.h | 2 +- src/include/optimizer/planmain.h | 2 +- src/include/rewrite/rowsecurity.h | 2 +- 19 files changed, 114 insertions(+), 125 deletions(-) diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMai= n.c index 85ff46b..d344b09 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -1738,17 +1738,17 @@ ExecConstraints(ResultRelInfo *resultRelInfo, } =20 /* - * ExecWithCheckOptions -- check that tuple satisfies any WITH CHECK OPTIO= Ns + * ExecCheckClauses -- check that tuple satisfies any inserted CHECK claus= es, * of the specified kind. * * Note that this needs to be called multiple times to ensure that all kin= ds of - * WITH CHECK OPTIONs are handled (both those from views which have the WI= TH - * CHECK OPTION set and from row level security policies). See ExecInsert= () - * and ExecUpdate(). + * CHECK clauses are handled (both those from views which have the WITH CH= ECK + * OPTION set and from row level security policies). See ExecInsert() and + * ExecUpdate(). */ void -ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo, - TupleTableSlot *slot, EState *estate) +ExecCheckClauses(WCOKind kind, ResultRelInfo *resultRelInfo, + TupleTableSlot *slot, EState *estate) { Relation rel =3D resultRelInfo->ri_RelationDesc; TupleDesc tupdesc =3D RelationGetDescr(rel); @@ -1766,8 +1766,8 @@ ExecWithCheckOptions(WCOKind kind, ResultRelInfo *res= ultRelInfo, econtext->ecxt_scantuple =3D slot; =20 /* Check each of the constraints */ - forboth(l1, resultRelInfo->ri_WithCheckOptions, - l2, resultRelInfo->ri_WithCheckOptionExprs) + forboth(l1, resultRelInfo->ri_InsertedCheckClauses, + l2, resultRelInfo->ri_InsertedCheckClauseExprs) { WithCheckOption *wco =3D (WithCheckOption *) lfirst(l1); ExprState *wcoExpr =3D (ExprState *) lfirst(l2); diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/= nodeModifyTable.c index 1ef76d0..a310299 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -321,12 +321,11 @@ ExecInsert(ModifyTableState *mtstate, /* * Check any RLS INSERT WITH CHECK policies * - * ExecWithCheckOptions() will skip any WCOs which are not of the kind + * ExecCheckClauses() will skip any WCOs which are not of the kind * we are looking for at this point. */ - if (resultRelInfo->ri_WithCheckOptions !=3D NIL) - ExecWithCheckOptions(WCO_RLS_INSERT_CHECK, - resultRelInfo, slot, estate); + if (resultRelInfo->ri_InsertedCheckClauses !=3D NIL) + ExecCheckClauses(WCO_RLS_INSERT_CHECK, resultRelInfo, slot, estate); =20 /* * Check the constraints of the tuple @@ -479,14 +478,14 @@ ExecInsert(ModifyTableState *mtstate, * violations per the SQL spec, so we do it after actually inserting the * record into the heap and all indexes. * - * ExecWithCheckOptions will elog(ERROR) if a violation is found, so the + * ExecCheckClauses will elog(ERROR) if a violation is found, so the * tuple will never be seen, if it violates the WITH CHECK OPTION. * - * ExecWithCheckOptions() will skip any WCOs which are not of the kind we + * ExecCheckClauses() will skip any WCOs which are not of the kind we * are looking for at this point. */ - if (resultRelInfo->ri_WithCheckOptions !=3D NIL) - ExecWithCheckOptions(WCO_VIEW_CHECK, resultRelInfo, slot, estate); + if (resultRelInfo->ri_InsertedCheckClauses !=3D NIL) + ExecCheckClauses(WCO_VIEW_CHECK, resultRelInfo, slot, estate); =20 /* Process RETURNING if present */ if (resultRelInfo->ri_projectReturning) @@ -858,13 +857,12 @@ ExecUpdate(ItemPointer tupleid, * triggers then trigger.c will have done heap_lock_tuple to lock the * correct tuple, so there's no need to do them again.) * - * ExecWithCheckOptions() will skip any WCOs which are not of the kind + * ExecCheckClauses() will skip any WCOs which are not of the kind * we are looking for at this point. */ lreplace:; - if (resultRelInfo->ri_WithCheckOptions !=3D NIL) - ExecWithCheckOptions(WCO_RLS_UPDATE_CHECK, - resultRelInfo, slot, estate); + if (resultRelInfo->ri_InsertedCheckClauses !=3D NIL) + ExecCheckClauses(WCO_RLS_UPDATE_CHECK, resultRelInfo, slot, estate); =20 /* * Check the constraints of the tuple @@ -993,11 +991,11 @@ lreplace:; * violations per the SQL spec, so we do it after actually updating the * record in the heap and all indexes. * - * ExecWithCheckOptions() will skip any WCOs which are not of the kind we + * ExecCheckClauses() will skip any WCOs which are not of the kind we * are looking for at this point. */ - if (resultRelInfo->ri_WithCheckOptions !=3D NIL) - ExecWithCheckOptions(WCO_VIEW_CHECK, resultRelInfo, slot, estate); + if (resultRelInfo->ri_InsertedCheckClauses !=3D NIL) + ExecCheckClauses(WCO_VIEW_CHECK, resultRelInfo, slot, estate); =20 /* Process RETURNING if present */ if (resultRelInfo->ri_projectReturning) @@ -1156,7 +1154,7 @@ ExecOnConflictUpdate(ModifyTableState *mtstate, return true; /* done with the tuple */ } =20 - if (resultRelInfo->ri_WithCheckOptions !=3D NIL) + if (resultRelInfo->ri_InsertedCheckClauses !=3D NIL) { /* * Check target's existing tuple against UPDATE-applicable USING @@ -1173,9 +1171,9 @@ ExecOnConflictUpdate(ModifyTableState *mtstate, * kinds, so there is no danger of spurious over-enforcement in the * INSERT or UPDATE path. */ - ExecWithCheckOptions(WCO_RLS_CONFLICT_CHECK, resultRelInfo, - mtstate->mt_existing, - mtstate->ps.state); + ExecCheckClauses(WCO_RLS_CONFLICT_CHECK, resultRelInfo, + mtstate->mt_existing, + mtstate->ps.state); } =20 /* Project the new tuple version */ @@ -1570,11 +1568,12 @@ ExecInitModifyTable(ModifyTable *node, EState *esta= te, int eflags) estate->es_result_relation_info =3D saved_resultRelInfo; =20 /* - * Initialize any WITH CHECK OPTION constraints if needed. + * Initialize any inserted CHECK clauses (which would have come from + * view WITH CHECK OPTION constraints or RLS), if needed. */ resultRelInfo =3D mtstate->resultRelInfo; i =3D 0; - foreach(l, node->withCheckOptionLists) + foreach(l, node->insertedCheckClauses) { List *wcoList =3D (List *) lfirst(l); List *wcoExprs =3D NIL; @@ -1589,8 +1588,8 @@ ExecInitModifyTable(ModifyTable *node, EState *estate= , int eflags) wcoExprs =3D lappend(wcoExprs, wcoExpr); } =20 - resultRelInfo->ri_WithCheckOptions =3D wcoList; - resultRelInfo->ri_WithCheckOptionExprs =3D wcoExprs; + resultRelInfo->ri_InsertedCheckClauses =3D wcoList; + resultRelInfo->ri_InsertedCheckClauseExprs =3D wcoExprs; resultRelInfo++; i++; } diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c index 62355aa..3fbf21a 100644 --- a/src/backend/nodes/copyfuncs.c +++ b/src/backend/nodes/copyfuncs.c @@ -181,7 +181,6 @@ _copyModifyTable(const ModifyTable *from) COPY_NODE_FIELD(resultRelations); COPY_SCALAR_FIELD(resultRelIndex); COPY_NODE_FIELD(plans); - COPY_NODE_FIELD(withCheckOptionLists); COPY_NODE_FIELD(returningLists); COPY_NODE_FIELD(fdwPrivLists); COPY_NODE_FIELD(rowMarks); @@ -192,6 +191,7 @@ _copyModifyTable(const ModifyTable *from) COPY_NODE_FIELD(onConflictWhere); COPY_SCALAR_FIELD(exclRelRTI); COPY_NODE_FIELD(exclRelTlist); + COPY_NODE_FIELD(insertedCheckClauses); =20 return newnode; } @@ -2702,7 +2702,6 @@ _copyQuery(const Query *from) COPY_NODE_FIELD(rtable); COPY_NODE_FIELD(jointree); COPY_NODE_FIELD(targetList); - COPY_NODE_FIELD(withCheckOptions); COPY_NODE_FIELD(onConflict); COPY_NODE_FIELD(returningList); COPY_NODE_FIELD(groupClause); @@ -2716,6 +2715,7 @@ _copyQuery(const Query *from) COPY_NODE_FIELD(rowMarks); COPY_NODE_FIELD(setOperations); COPY_NODE_FIELD(constraintDeps); + COPY_NODE_FIELD(insertedCheckClauses); =20 return newnode; } diff --git a/src/backend/nodes/equalfuncs.c b/src/backend/nodes/equalfuncs.c index 8f16833..fd1a074 100644 --- a/src/backend/nodes/equalfuncs.c +++ b/src/backend/nodes/equalfuncs.c @@ -906,7 +906,6 @@ _equalQuery(const Query *a, const Query *b) COMPARE_NODE_FIELD(rtable); COMPARE_NODE_FIELD(jointree); COMPARE_NODE_FIELD(targetList); - COMPARE_NODE_FIELD(withCheckOptions); COMPARE_NODE_FIELD(onConflict); COMPARE_NODE_FIELD(returningList); COMPARE_NODE_FIELD(groupClause); @@ -920,6 +919,7 @@ _equalQuery(const Query *a, const Query *b) COMPARE_NODE_FIELD(rowMarks); COMPARE_NODE_FIELD(setOperations); COMPARE_NODE_FIELD(constraintDeps); + COMPARE_NODE_FIELD(insertedCheckClauses); =20 return true; } diff --git a/src/backend/nodes/nodeFuncs.c b/src/backend/nodes/nodeFuncs.c index a11cb9f..521af70 100644 --- a/src/backend/nodes/nodeFuncs.c +++ b/src/backend/nodes/nodeFuncs.c @@ -2047,7 +2047,7 @@ query_tree_walker(Query *query, =20 if (walker((Node *) query->targetList, context)) return true; - if (walker((Node *) query->withCheckOptions, context)) + if (walker((Node *) query->insertedCheckClauses, context)) return true; if (walker((Node *) query->onConflict, context)) return true; @@ -2853,7 +2853,7 @@ query_tree_mutator(Query *query, } =20 MUTATE(query->targetList, query->targetList, List *); - MUTATE(query->withCheckOptions, query->withCheckOptions, List *); + MUTATE(query->insertedCheckClauses, query->insertedCheckClauses, List *); MUTATE(query->onConflict, query->onConflict, OnConflictExpr *); MUTATE(query->returningList, query->returningList, List *); MUTATE(query->jointree, query->jointree, FromExpr *); diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index c91273c..9a9855e 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -335,7 +335,6 @@ _outModifyTable(StringInfo str, const ModifyTable *node) WRITE_NODE_FIELD(resultRelations); WRITE_INT_FIELD(resultRelIndex); WRITE_NODE_FIELD(plans); - WRITE_NODE_FIELD(withCheckOptionLists); WRITE_NODE_FIELD(returningLists); WRITE_NODE_FIELD(fdwPrivLists); WRITE_NODE_FIELD(rowMarks); @@ -2385,7 +2384,6 @@ _outQuery(StringInfo str, const Query *node) WRITE_NODE_FIELD(rtable); WRITE_NODE_FIELD(jointree); WRITE_NODE_FIELD(targetList); - WRITE_NODE_FIELD(withCheckOptions); WRITE_NODE_FIELD(onConflict); WRITE_NODE_FIELD(returningList); WRITE_NODE_FIELD(groupClause); diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c index 08519ed..5c82c42 100644 --- a/src/backend/nodes/readfuncs.c +++ b/src/backend/nodes/readfuncs.c @@ -244,7 +244,6 @@ _readQuery(void) READ_NODE_FIELD(rtable); READ_NODE_FIELD(jointree); READ_NODE_FIELD(targetList); - READ_NODE_FIELD(withCheckOptions); READ_NODE_FIELD(onConflict); READ_NODE_FIELD(returningList); READ_NODE_FIELD(groupClause); @@ -292,23 +291,6 @@ _readDeclareCursorStmt(void) } =20 /* - * _readWithCheckOption - */ -static WithCheckOption * -_readWithCheckOption(void) -{ - READ_LOCALS(WithCheckOption); - - READ_ENUM_FIELD(kind, WCOKind); - READ_STRING_FIELD(relname); - READ_STRING_FIELD(polname); - READ_NODE_FIELD(qual); - READ_BOOL_FIELD(cascaded); - - READ_DONE(); -} - -/* * _readSortGroupClause */ static SortGroupClause * @@ -1466,7 +1448,6 @@ _readModifyTable(void) READ_NODE_FIELD(resultRelations); READ_INT_FIELD(resultRelIndex); READ_NODE_FIELD(plans); - READ_NODE_FIELD(withCheckOptionLists); READ_NODE_FIELD(returningLists); READ_NODE_FIELD(fdwPrivLists); READ_NODE_FIELD(rowMarks); @@ -2180,8 +2161,6 @@ parseNodeString(void) =20 if (MATCH("QUERY", 5)) return_value =3D _readQuery(); - else if (MATCH("WITHCHECKOPTION", 15)) - return_value =3D _readWithCheckOption(); else if (MATCH("SORTGROUPCLAUSE", 15)) return_value =3D _readSortGroupClause(); else if (MATCH("GROUPINGSET", 11)) diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimize= r/plan/createplan.c index 404c6f5..1fc52de 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -4959,7 +4959,7 @@ make_modifytable(PlannerInfo *root, CmdType operation, bool canSetTag, Index nominalRelation, List *resultRelations, List *subplans, - List *withCheckOptionLists, List *returningLists, + List *insertedCheckClauses, List *returningLists, List *rowMarks, OnConflictExpr *onconflict, int epqParam) { ModifyTable *node =3D makeNode(ModifyTable); @@ -4971,8 +4971,8 @@ make_modifytable(PlannerInfo *root, int i; =20 Assert(list_length(resultRelations) =3D=3D list_length(subplans)); - Assert(withCheckOptionLists =3D=3D NIL || - list_length(resultRelations) =3D=3D list_length(withCheckOptionLists)= ); + Assert(insertedCheckClauses =3D=3D NIL || + list_length(resultRelations) =3D=3D list_length(insertedCheckClauses)= ); Assert(returningLists =3D=3D NIL || list_length(resultRelations) =3D=3D list_length(returningLists)); =20 @@ -5036,7 +5036,7 @@ make_modifytable(PlannerInfo *root, node->exclRelRTI =3D onconflict->exclRelIndex; node->exclRelTlist =3D onconflict->exclRelTlist; } - node->withCheckOptionLists =3D withCheckOptionLists; + node->insertedCheckClauses =3D insertedCheckClauses; node->returningLists =3D returningLists; node->rowMarks =3D rowMarks; node->epqParam =3D epqParam; diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/p= lan/planner.c index 06be922..f04b02e 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -378,7 +378,7 @@ subquery_planner(PlannerGlobal *glob, Query *parse, { PlannerInfo *root; Plan *plan; - List *newWithCheckOptions; + List *newCheckClauses; List *newHaving; bool hasOuterJoins; ListCell *l; @@ -508,17 +508,21 @@ subquery_planner(PlannerGlobal *glob, Query *parse, preprocess_expression(root, (Node *) parse->targetList, EXPRKIND_TARGET); =20 - newWithCheckOptions =3D NIL; - foreach(l, parse->withCheckOptions) + /* + * Process any inserted CHECK clauses (built when WITH CHECK OPTION is + * specified or RLS is used). + */ + newCheckClauses =3D NIL; + foreach(l, parse->insertedCheckClauses) { WithCheckOption *wco =3D (WithCheckOption *) lfirst(l); =20 wco->qual =3D preprocess_expression(root, wco->qual, EXPRKIND_QUAL); if (wco->qual !=3D NULL) - newWithCheckOptions =3D lappend(newWithCheckOptions, wco); + newCheckClauses =3D lappend(newCheckClauses, wco); } - parse->withCheckOptions =3D newWithCheckOptions; + parse->insertedCheckClauses =3D newCheckClauses; =20 parse->returningList =3D (List *) preprocess_expression(root, (Node *) parse->returningList, @@ -677,18 +681,19 @@ subquery_planner(PlannerGlobal *glob, Query *parse, /* If it's not SELECT, we need a ModifyTable node */ if (parse->commandType !=3D CMD_SELECT) { - List *withCheckOptionLists; + List *newCheckClausesList; List *returningLists; List *rowMarks; =20 /* - * Set up the WITH CHECK OPTION and RETURNING lists-of-lists, if + * Set up the inserted CHECK clauses (for when a view has WITH CHECK + * specified or RLS is being used), and RETURNING lists-of-lists, if * needed. */ - if (parse->withCheckOptions) - withCheckOptionLists =3D list_make1(parse->withCheckOptions); + if (parse->insertedCheckClauses) + newCheckClausesList =3D list_make1(parse->insertedCheckClauses); else - withCheckOptionLists =3D NIL; + newCheckClausesList =3D NIL; =20 if (parse->returningList) returningLists =3D list_make1(parse->returningList); @@ -711,7 +716,7 @@ subquery_planner(PlannerGlobal *glob, Query *parse, parse->resultRelation, list_make1_int(parse->resultRelation), list_make1(plan), - withCheckOptionLists, + newCheckClausesList, returningLists, rowMarks, parse->onConflict, @@ -909,7 +914,7 @@ inheritance_planner(PlannerInfo *root) RelOptInfo **save_rel_array =3D NULL; List *subplans =3D NIL; List *resultRelations =3D NIL; - List *withCheckOptionLists =3D NIL; + List *insertedCheckClauses =3D NIL; List *returningLists =3D NIL; List *rowMarks; ListCell *lc; @@ -1228,10 +1233,13 @@ inheritance_planner(PlannerInfo *root) /* Build list of target-relation RT indexes */ resultRelations =3D lappend_int(resultRelations, appinfo->child_relid); =20 - /* Build lists of per-relation WCO and RETURNING targetlists */ - if (parse->withCheckOptions) - withCheckOptionLists =3D lappend(withCheckOptionLists, - subroot.parse->withCheckOptions); + /* + * Build lists of per-relation CHECK clauses (from views which have + * WITH CHECK specified or if RLS is used) and RETURNING targetlists + */ + if (parse->insertedCheckClauses) + insertedCheckClauses =3D lappend(insertedCheckClauses, + subroot.parse->insertedCheckClauses); if (parse->returningList) returningLists =3D lappend(returningLists, subroot.parse->returningList); @@ -1283,7 +1291,7 @@ inheritance_planner(PlannerInfo *root) nominalRelation, resultRelations, subplans, - withCheckOptionLists, + insertedCheckClauses, returningLists, rowMarks, NULL, diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/p= lan/setrefs.c index daeb584..b33cc96 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -710,8 +710,8 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffs= et) Assert(splan->plan.targetlist =3D=3D NIL); Assert(splan->plan.qual =3D=3D NIL); =20 - splan->withCheckOptionLists =3D - fix_scan_list(root, splan->withCheckOptionLists, rtoffset); + splan->insertedCheckClauses =3D + fix_scan_list(root, splan->insertedCheckClauses, rtoffset); =20 if (splan->returningLists) { diff --git a/src/backend/optimizer/prep/prepsecurity.c b/src/backend/optimi= zer/prep/prepsecurity.c index c4b61df..ba65ebb 100644 --- a/src/backend/optimizer/prep/prepsecurity.c +++ b/src/backend/optimizer/prep/prepsecurity.c @@ -138,7 +138,7 @@ expand_security_quals(PlannerInfo *root, List *tlist) ChangeVarNodes((Node *) parse->returningList, rt_index, parse->resultRelation, 0); =20 - ChangeVarNodes((Node *) parse->withCheckOptions, rt_index, + ChangeVarNodes((Node *) parse->insertedCheckClauses, rt_index, parse->resultRelation, 0); } =20 diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rew= riteHandler.c index 1b8e7b0..6867372 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -1770,7 +1770,7 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool= forUpdatePushedDown) RangeTblEntry *rte =3D (RangeTblEntry *) lfirst(lc); Relation rel; List *securityQuals; - List *withCheckOptions; + List *insertedCheckClauses; bool hasRowSecurity; bool hasSubLinks; =20 @@ -1787,10 +1787,10 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bo= ol forUpdatePushedDown) * Fetch any new security quals that must be applied to this RTE. */ get_row_security_policies(parsetree, rte, rt_index, - &securityQuals, &withCheckOptions, + &securityQuals, &insertedCheckClauses, &hasRowSecurity, &hasSubLinks); =20 - if (securityQuals !=3D NIL || withCheckOptions !=3D NIL) + if (securityQuals !=3D NIL || insertedCheckClauses !=3D NIL) { if (hasSubLinks) { @@ -1810,15 +1810,16 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bo= ol forUpdatePushedDown) =20 /* * get_row_security_policies just passed back securityQuals - * and/or withCheckOptions, and there were SubLinks, make sure - * we lock any relations which are referenced. + * and/or insertedCheckClauses, and there were SubLinks, make + * sure we lock any relations which are referenced. * * These locks would normally be acquired by the parser, but - * securityQuals and withCheckOptions are added post-parsing. + * securityQuals and insertedCheckClauses are added + * post-parsing. */ context.for_execute =3D true; (void) acquireLocksOnSubLinks((Node *) securityQuals, &context); - (void) acquireLocksOnSubLinks((Node *) withCheckOptions, + (void) acquireLocksOnSubLinks((Node *) insertedCheckClauses, &context); =20 /* @@ -1828,7 +1829,7 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool= forUpdatePushedDown) expression_tree_walker((Node *) securityQuals, fireRIRonSubLink, (void *) activeRIRs); =20 - expression_tree_walker((Node *) withCheckOptions, + expression_tree_walker((Node *) insertedCheckClauses, fireRIRonSubLink, (void *) activeRIRs); =20 activeRIRs =3D list_delete_first(activeRIRs); @@ -1843,8 +1844,8 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool= forUpdatePushedDown) rte->securityQuals =3D list_concat(securityQuals, rte->securityQuals); =20 - parsetree->withCheckOptions =3D list_concat(withCheckOptions, - parsetree->withCheckOptions); + parsetree->insertedCheckClauses =3D list_concat(insertedCheckClauses, + parsetree->insertedCheckClauses); } =20 /* @@ -2983,7 +2984,7 @@ rewriteTargetView(Query *parsetree, Relation view) /* * For INSERT/UPDATE, if the view has the WITH CHECK OPTION, or any parent * view specified WITH CASCADED CHECK OPTION, add the quals from the view - * to the query's withCheckOptions list. + * to the query's insertedCheckClauses list. */ if (parsetree->commandType !=3D CMD_DELETE) { @@ -2994,14 +2995,14 @@ rewriteTargetView(Query *parsetree, Relation view) * If the parent view has a cascaded check option, treat this view as * if it also had a cascaded check option. * - * New WithCheckOptions are added to the start of the list, so if - * there is a cascaded check option, it will be the first item in the - * list. + * New WithCheckOptions are added to the start of the + * insertedCheckClauses list, so if there is a cascaded check option, + * it will be the first item in the list. */ - if (parsetree->withCheckOptions !=3D NIL) + if (parsetree->insertedCheckClauses !=3D NIL) { WithCheckOption *parent_wco =3D - (WithCheckOption *) linitial(parsetree->withCheckOptions); + (WithCheckOption *) linitial(parsetree->insertedCheckClauses); =20 if (parent_wco->cascaded) { @@ -3030,8 +3031,8 @@ rewriteTargetView(Query *parsetree, Relation view) wco->qual =3D NULL; wco->cascaded =3D cascaded; =20 - parsetree->withCheckOptions =3D lcons(wco, - parsetree->withCheckOptions); + parsetree->insertedCheckClauses =3D lcons(wco, + parsetree->insertedCheckClauses); =20 if (viewquery->jointree->quals !=3D NULL) { diff --git a/src/backend/rewrite/rowsecurity.c b/src/backend/rewrite/rowsec= urity.c index c20a178..42108af 100644 --- a/src/backend/rewrite/rowsecurity.c +++ b/src/backend/rewrite/rowsecurity.c @@ -77,7 +77,7 @@ static void add_with_check_options(Relation rel, WCOKind kind, List *permissive_policies, List *restrictive_policies, - List **withCheckOptions, + List **insertedCheckClauses, bool *hasSubLinks); =20 static bool check_role_for_policy(ArrayType *policy_roles, Oid user_id); @@ -104,7 +104,7 @@ row_security_policy_hook_type row_security_policy_hook_= restrictive =3D NULL; */ void get_row_security_policies(Query *root, RangeTblEntry *rte, int rt_index, - List **securityQuals, List **withCheckOptions, + List **securityQuals, List **insertedCheckClauses, bool *hasRowSecurity, bool *hasSubLinks) { Oid user_id; @@ -116,7 +116,7 @@ get_row_security_policies(Query *root, RangeTblEntry *r= te, int rt_index, =20 /* Defaults for the return values */ *securityQuals =3D NIL; - *withCheckOptions =3D NIL; + *insertedCheckClauses =3D NIL; *hasRowSecurity =3D false; *hasSubLinks =3D false; =20 @@ -214,7 +214,7 @@ get_row_security_policies(Query *root, RangeTblEntry *r= te, int rt_index, } =20 /* - * For INSERT and UPDATE, add withCheckOptions to verify that any new + * For INSERT and UPDATE, add insertedCheckClauses to verify that any new * records added are consistent with the security policies. This will use * each policy's WITH CHECK clause, or its USING clause if no explicit * WITH CHECK clause is defined. @@ -229,7 +229,7 @@ get_row_security_policies(Query *root, RangeTblEntry *r= te, int rt_index, WCO_RLS_INSERT_CHECK : WCO_RLS_UPDATE_CHECK, permissive_policies, restrictive_policies, - withCheckOptions, + insertedCheckClauses, hasSubLinks); =20 /* @@ -257,7 +257,7 @@ get_row_security_policies(Query *root, RangeTblEntry *r= te, int rt_index, WCO_RLS_CONFLICT_CHECK, conflict_permissive_policies, conflict_restrictive_policies, - withCheckOptions, + insertedCheckClauses, hasSubLinks); =20 /* @@ -276,7 +276,7 @@ get_row_security_policies(Query *root, RangeTblEntry *r= te, int rt_index, WCO_RLS_CONFLICT_CHECK, conflict_returning_permissive_policies, conflict_returning_restrictive_policies, - withCheckOptions, + insertedCheckClauses, hasSubLinks); } =20 @@ -285,7 +285,7 @@ get_row_security_policies(Query *root, RangeTblEntry *r= te, int rt_index, WCO_RLS_UPDATE_CHECK, conflict_permissive_policies, conflict_restrictive_policies, - withCheckOptions, + insertedCheckClauses, hasSubLinks); } } @@ -565,8 +565,8 @@ add_security_quals(int rt_index, * a WCO_RLS_CONFLICT_CHECK WithCheckOption, which always uses the USING * clauses from RLS policies. * - * New WCOs are added to withCheckOptions, and hasSubLinks is set to true = if - * any of the check clauses added contain sublink subqueries. + * New WCOs are added to insertedCheckClauses, and hasSubLinks is set to t= rue + * if any of the check clauses added contain sublink subqueries. */ static void add_with_check_options(Relation rel, @@ -574,7 +574,7 @@ add_with_check_options(Relation rel, WCOKind kind, List *permissive_policies, List *restrictive_policies, - List **withCheckOptions, + List **insertedCheckClauses, bool *hasSubLinks) { ListCell *item; @@ -631,7 +631,7 @@ add_with_check_options(Relation rel, =20 ChangeVarNodes(wco->qual, 1, rt_index, 0); =20 - *withCheckOptions =3D lappend(*withCheckOptions, wco); + *insertedCheckClauses =3D lappend(*insertedCheckClauses, wco); =20 /* * Now add WithCheckOptions for each of the restrictive policy clauses @@ -657,7 +657,7 @@ add_with_check_options(Relation rel, wco->qual =3D (Node *) qual; wco->cascaded =3D false; =20 - *withCheckOptions =3D lappend(*withCheckOptions, wco); + *insertedCheckClauses =3D lappend(*insertedCheckClauses, wco); *hasSubLinks |=3D policy->hassublinks; } } @@ -679,7 +679,7 @@ add_with_check_options(Relation rel, false, true); wco->cascaded =3D false; =20 - *withCheckOptions =3D lappend(*withCheckOptions, wco); + *insertedCheckClauses =3D lappend(*insertedCheckClauses, wco); } } =20 diff --git a/src/include/executor/executor.h b/src/include/executor/executo= r.h index 226f905..2363b8a 100644 --- a/src/include/executor/executor.h +++ b/src/include/executor/executor.h @@ -193,7 +193,7 @@ extern ResultRelInfo *ExecGetTriggerResultRel(EState *e= state, Oid relid); extern bool ExecContextForcesOids(PlanState *planstate, bool *hasoids); extern void ExecConstraints(ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate); -extern void ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInf= o, +extern void ExecCheckClauses(WCOKind kind, ResultRelInfo *resultRelInfo, TupleTableSlot *slot, EState *estate); extern LockTupleMode ExecUpdateLockMode(EState *estate, ResultRelInfo *rel= info); extern ExecRowMark *ExecFindRowMark(EState *estate, Index rti, bool missin= g_ok); diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h index 4ae2f3e..cbf4896 100644 --- a/src/include/nodes/execnodes.h +++ b/src/include/nodes/execnodes.h @@ -311,8 +311,8 @@ typedef struct JunkFilter * TrigInstrument optional runtime measurements for triggers * FdwRoutine FDW callback functions, if foreign table * FdwState available to save private state of FDW - * WithCheckOptions list of WithCheckOption's to be checked - * WithCheckOptionExprs list of WithCheckOption expr states + * InsertedCheckClauses list of WithCheckOption's to be checked + * InsertedCheckClauseExprs list of WithCheckOption expr states * ConstraintExprs array of constraint-checking expr states * junkFilter for removing junk attributes from tuples * projectReturning for computing a RETURNING list @@ -334,8 +334,8 @@ typedef struct ResultRelInfo Instrumentation *ri_TrigInstrument; struct FdwRoutine *ri_FdwRoutine; void *ri_FdwState; - List *ri_WithCheckOptions; - List *ri_WithCheckOptionExprs; + List *ri_InsertedCheckClauses; + List *ri_InsertedCheckClauseExprs; List **ri_ConstraintExprs; JunkFilter *ri_junkFilter; ProjectionInfo *ri_projectReturning; diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 770866a..fe8597e 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -130,8 +130,6 @@ typedef struct Query =20 List *targetList; /* target list (of TargetEntry) */ =20 - List *withCheckOptions; /* a list of WithCheckOption's */ - OnConflictExpr *onConflict; /* ON CONFLICT DO [NOTHING | UPDATE] */ =20 List *returningList; /* return-values list (of TargetEntry) */ @@ -158,6 +156,12 @@ typedef struct Query =20 List *constraintDeps; /* a list of pg_constraint OIDs that the query * depends on to be semantically valid */ + + List *insertedCheckClauses; /* a list of WithCheckOption's, which + * are added during rewrite, therefore + * not written out as part of Query by + * outfuncs or read in by readfuncs */ + } Query; =20 =20 diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h index cc259f1..6d03f8d 100644 --- a/src/include/nodes/plannodes.h +++ b/src/include/nodes/plannodes.h @@ -179,7 +179,6 @@ typedef struct ModifyTable List *resultRelations; /* integer list of RT indexes */ int resultRelIndex; /* index of first resultRel in plan's list */ List *plans; /* plan(s) producing source data */ - List *withCheckOptionLists; /* per-target-table WCO lists */ List *returningLists; /* per-target-table RETURNING tlists */ List *fdwPrivLists; /* per-target-table FDW private data lists */ List *rowMarks; /* PlanRowMarks (non-locking only) */ @@ -190,6 +189,7 @@ typedef struct ModifyTable Node *onConflictWhere; /* WHERE for ON CONFLICT UPDATE */ Index exclRelRTI; /* RTI of the EXCLUDED pseudo relation */ List *exclRelTlist; /* tlist of the EXCLUDED pseudo relation */ + List *insertedCheckClauses; /* per-target-table WCO lists */ } ModifyTable; =20 /* ---------------- diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planm= ain.h index 52b077a..f8c9de0 100644 --- a/src/include/optimizer/planmain.h +++ b/src/include/optimizer/planmain.h @@ -86,7 +86,7 @@ extern ModifyTable *make_modifytable(PlannerInfo *root, CmdType operation, bool canSetTag, Index nominalRelation, List *resultRelations, List *subplans, - List *withCheckOptionLists, List *returningLists, + List *insertedCheckClauses, List *returningLists, List *rowMarks, OnConflictExpr *onconflict, int epqParam); extern bool is_projection_capable_plan(Plan *plan); =20 diff --git a/src/include/rewrite/rowsecurity.h b/src/include/rewrite/rowsec= urity.h index 4af244d..62823b7 100644 --- a/src/include/rewrite/rowsecurity.h +++ b/src/include/rewrite/rowsecurity.h @@ -42,7 +42,7 @@ extern PGDLLIMPORT row_security_policy_hook_type row_secu= rity_policy_hook_restri =20 extern void get_row_security_policies(Query *root, RangeTblEntry *rte, int rt_index, - List **securityQuals, List **withCheckOptions, + List **securityQuals, List **insertedCheckClauses, bool *hasRowSecurity, bool *hasSubLinks); =20 #endif /* ROWSECURITY_H */ --=20 1.9.1 --3ChEjlKQG30qDPT4-- --WZJyhX63VJL+5o8l Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJWBFLZAAoJEO1sijiDR2RVuI4QALHwnvv56TZQnUryS9iav1/K AiXO36aNqMKCtvpIMIwtLxzh4obD0ATcoxoI2OpVEstiVFJa7zryOJ8AZajE3dek BapIU+zUx6Ihji7Uejguc2ZfNwvKy5nz9e2wurmCXrwH9OF+7EHKwsrvtNLzxdrr kPmj7iKbQZvRdgdeISxQjkbYBEv7meVAoQkSHP6QaH5lkvnzbxu9Xeds4K3xreke ztc8k2a0nokrJrvOhco8rWpT3mmzmzS2Lu9goZdLbOVLkL1V+dsd0yvGJ2IF+W88 /BJQOUfLJ6nNEwcmjOZmku2CS5ZPHzYbMAaKA49NhRPmyKMDXyuL1ndpbkd4zm81 druvzJgR/WJyalm0eIr47ZFri0iATgLp7g5Fdc/UOFuyPrqQg1oDqyDpQ2Fu+5Db tqdYqAI3vz1LsW5lOQPJznAd+EqwYXyBVoFpvOAM9V/zOAnyovtZ4SNB9q8fP5Zb OwJ/F2REsE6bVvTJW3Khy1lQnnKchSJy1cF8NFv7AWzOtHWyL2Jh+wZ+rpRb9FAg Agg7biWadSJ9HDrekCOW++uQQChPCgRyozbJ4OFkDEkVKaUdwVSTludaTz48HFoT sYQ2DWzdcVv6lAgnsEWj8Rk1u/1D3+FwfV7o46hlWS1hmKFVadVzaTx0jQ86XChO boaMVutyWFQJf1jvaU2l =X4BS -----END PGP SIGNATURE----- --WZJyhX63VJL+5o8l--