68 bool *returning_flag);
79 const char *attrName);
90 int varno,
Query *parsetree,
bool *hasUpdate);
143 bool forUpdatePushedDown)
155 foreach(l, parsetree->
rtable)
181 else if (forUpdatePushedDown)
219 Var *aliasvar = aliasitem;
231 if (aliasvar &&
IsA(aliasvar,
Var))
243 if (aliasvar->
varno != curinputvarno)
245 curinputvarno = aliasvar->
varno;
246 if (curinputvarno >= rt_index)
247 elog(
ERROR,
"unexpected varno %d in JOIN RTE %d",
248 curinputvarno, rt_index);
249 curinputrte =
rt_fetch(curinputvarno,
259 newaliasvars =
lappend(newaliasvars, aliasitem);
272 (forUpdatePushedDown ||
294 if (parsetree->hasSubLinks)
349 bool *returning_flag)
355 Query **sub_action_ptr;
374 current_varno = rt_index;
404 foreach(lc, sub_action->
rtable)
442 List *perminfos_tail = sub_action->rteperminfos;
450 sub_action->rteperminfos =
copyObject(parsetree->rteperminfos);
452 rtable_tail, perminfos_tail);
459 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
461 foreach(lc, parsetree->
rtable)
468 sub_action->hasSubLinks =
472 sub_action->hasSubLinks =
476 sub_action->hasSubLinks =
480 sub_action->hasSubLinks =
487 sub_action->hasSubLinks |=
489 if (sub_action->hasSubLinks)
501 sub_action->hasRowSecurity |= parsetree->hasRowSecurity;
528 if (newjointree !=
NIL)
538 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
539 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
548 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
549 sub_action->hasSubLinks =
571 foreach(lc, parsetree->
cteList)
576 foreach(lc2, sub_action->
cteList)
582 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
583 errmsg(
"WITH query name \"%s\" appears in both a rule action and the query being rewritten",
592 sub_action->hasRecursive |= parsetree->hasRecursive;
593 sub_action->hasModifyingCTE |= parsetree->hasModifyingCTE;
607 if (sub_action->hasModifyingCTE && rule_action != sub_action)
609 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
610 errmsg(
"INSERT ... SELECT rule actions are not supported for queries having data-modifying statements in WITH")));
618 AddQual(sub_action, rule_qual);
633 sub_action = (
Query *)
645 *sub_action_ptr = sub_action;
647 rule_action = sub_action;
662 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
663 errmsg(
"cannot have RETURNING lists in multiple rules")));
664 *returning_flag =
true;
667 parsetree->resultRelation,
674 &rule_action->hasSubLinks);
680 if (parsetree->hasSubLinks && !rule_action->hasSubLinks)
681 rule_action->hasSubLinks =
704 foreach(l, newjointree)
764 int values_rte_index,
788 next_junk_attrno = numattrs + 1;
790 foreach(temp, targetList)
794 if (!old_tle->resjunk)
797 attrno = old_tle->
resno;
798 if (attrno < 1 || attrno > numattrs)
799 elog(
ERROR,
"bogus resno %d in targetlist", attrno);
803 if (att_tup->attisdropped)
807 new_tles[attrno - 1] =
809 new_tles[attrno - 1],
824 if (old_tle->
resno != next_junk_attrno)
827 old_tle->
resno = next_junk_attrno;
829 junk_tlist =
lappend(junk_tlist, old_tle);
834 for (attrno = 1; attrno <= numattrs; attrno++)
842 if (att_tup->attisdropped)
850 apply_default = ((new_tle == NULL && commandType ==
CMD_INSERT) ||
855 int values_attrno = 0;
858 if (values_rte && new_tle &&
IsA(new_tle->
expr,
Var))
862 if (var->
varno == values_rte_index)
871 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS && !apply_default)
874 apply_default =
true;
883 if (values_attrno != 0)
885 if (default_only_cols == NULL)
889 apply_default =
true;
894 (
errcode(ERRCODE_GENERATED_ALWAYS),
895 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
897 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
899 errhint(
"Use OVERRIDING SYSTEM VALUE to override.")));
908 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_BY_DEFAULT &&
910 apply_default =
true;
916 if (att_tup->attgenerated && !apply_default)
922 if (values_attrno != 0)
924 if (default_only_cols == NULL)
928 apply_default =
true;
933 (
errcode(ERRCODE_GENERATED_ALWAYS),
934 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
936 errdetail(
"Column \"%s\" is a generated column.",
945 if (values_attrno != 0 && apply_default && unused_values_attrnos)
957 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS &&
958 new_tle && !apply_default)
960 (
errcode(ERRCODE_GENERATED_ALWAYS),
961 errmsg(
"column \"%s\" can only be updated to DEFAULT",
963 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
966 if (att_tup->attgenerated && new_tle && !apply_default)
968 (
errcode(ERRCODE_GENERATED_ALWAYS),
969 errmsg(
"column \"%s\" can only be updated to DEFAULT",
971 errdetail(
"Column \"%s\" is a generated column.",
975 if (att_tup->attgenerated)
982 else if (apply_default)
1003 att_tup->attcollation,
1027 new_tlist =
lappend(new_tlist, new_tle);
1045 const char *attrName)
1056 if (prior_tle == NULL)
1096 prior_expr = (
Node *) prior_tle->
expr;
1111 if (src_input == NULL ||
1112 prior_input == NULL ||
1115 (
errcode(ERRCODE_SYNTAX_ERROR),
1116 errmsg(
"multiple assignments to same column \"%s\"",
1122 priorbottom = prior_input;
1127 if (newbottom == NULL)
1129 priorbottom = newbottom;
1131 if (!
equal(priorbottom, src_input))
1133 (
errcode(ERRCODE_SYNTAX_ERROR),
1134 errmsg(
"multiple assignments to same column \"%s\"",
1147 memcpy(fstore, prior_expr,
sizeof(
FieldStore));
1158 memcpy(fstore, src_expr,
sizeof(
FieldStore));
1159 fstore->
arg = (
Expr *) prior_expr;
1161 newexpr = (
Node *) fstore;
1169 newexpr = (
Node *) sbsref;
1183 newcoerce->
arg = (
Expr *) newexpr;
1184 newexpr = (
Node *) newcoerce;
1229 Oid atttype = att_tup->atttypid;
1230 int32 atttypmod = att_tup->atttypmod;
1234 if (att_tup->attidentity)
1239 nve->
typeId = att_tup->atttypid;
1241 return (
Node *) nve;
1247 if (att_tup->atthasdef)
1251 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1259 if (expr == NULL && !att_tup->attgenerated)
1282 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1283 errmsg(
"column \"%s\" is of type %s"
1284 " but default expression is of type %s",
1288 errhint(
"You will need to rewrite or cast the expression.")));
1305 foreach(lc2, sublist)
1333 if (default_only_cols == NULL)
1337 foreach(lc2, sublist)
1350 foreach(lc2, sublist)
1368 return default_only_cols;
1416 bool isAutoUpdatableView;
1441 attrnos = (
int *)
palloc0(numattrs *
sizeof(
int));
1455 Assert(attrno >= 1 && attrno <= numattrs);
1456 attrnos[attrno - 1] = tle->
resno;
1466 isAutoUpdatableView =
false;
1467 if (target_relation->
rd_rel->relkind == RELKIND_VIEW &&
1477 parsetree->resultRelation, parsetree, &hasUpdate);
1485 rule_lock->
qual == NULL)
1498 isAutoUpdatableView =
true;
1513 foreach(lc2, sublist)
1516 int attrno = attrnos[
i++];
1540 elog(
ERROR,
"cannot set value in column %d to DEFAULT",
i);
1541 Assert(attrno > 0 && attrno <= target_relation->rd_att->natts);
1544 if (!att_tup->attisdropped)
1556 if (isAutoUpdatableView)
1559 newList =
lappend(newList, col);
1560 allReplaced =
false;
1566 att_tup->attcollation,
1580 newList =
lappend(newList, new_expr);
1583 newList =
lappend(newList, col);
1585 newValues =
lappend(newValues, newList);
1617 foreach(lc2, sublist)
1630 newList =
lappend(newList, col);
1632 newValues =
lappend(newValues, newList);
1653 if (rulelocks == NULL)
1662 if (parsetree->resultRelation != varno)
1668 for (
i = 0;
i < nlocks;
i++)
1697 if (oneLock->
event == event)
1701 matching_locks =
lappend(matching_locks, oneLock);
1705 return matching_locks;
1725 elog(
ERROR,
"expected just one rule action");
1726 if (
rule->qual != NULL)
1727 elog(
ERROR,
"cannot handle qualified ON SELECT rule");
1729 if (rt_index == parsetree->resultRelation)
1773 parsetree->resultRelation, 0);
1792 elog(
ERROR,
"unrecognized commandType: %d",
1902 strength, waitPolicy,
true);
1922 elog(
ERROR,
"unrecognized node type: %d",
1960 (
void *) activeRIRs);
1974 int origResultRelation = parsetree->resultRelation;
1984 foreach(lc, parsetree->
cteList)
1988 if (cte->search_clause || cte->cycle_clause)
2040 if (rte->
relkind == RELKIND_MATVIEW)
2061 if (rt_index != parsetree->resultRelation &&
2069 if (rt_index == parsetree->resultRelation &&
2070 rt_index != origResultRelation)
2086 for (
i = 0;
i <
rules->numLocks;
i++)
2104 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2105 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
2128 foreach(lc, parsetree->
cteList)
2140 if (parsetree->hasSubLinks)
2151 foreach(lc, parsetree->
rtable)
2155 List *securityQuals;
2156 List *withCheckOptions;
2157 bool hasRowSecurity;
2164 (rte->
relkind != RELKIND_RELATION &&
2165 rte->
relkind != RELKIND_PARTITIONED_TABLE))
2174 &securityQuals, &withCheckOptions,
2175 &hasRowSecurity, &hasSubLinks);
2177 if (securityQuals !=
NIL || withCheckOptions !=
NIL)
2189 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2190 errmsg(
"infinite recursion detected in policy for relation \"%s\"",
2230 parsetree->withCheckOptions =
list_concat(withCheckOptions,
2231 parsetree->withCheckOptions);
2239 parsetree->hasRowSecurity =
true;
2241 parsetree->hasSubLinks =
true;
2297 &parsetree->hasSubLinks);
2339 bool *returning_flag,
2340 Query **qual_product)
2348 Node *event_qual = rule_lock->
qual;
2356 if (event_qual != NULL)
2361 *instead_flag =
true;
2383 if (*qual_product == NULL)
2401 event_qual, rt_index, event,
2404 rule_action->querySource = qsrc;
2405 rule_action->canSetTag =
false;
2407 results =
lappend(results, rule_action);
2439 elog(
ERROR,
"invalid _RETURN rule action specification");
2445 elog(
ERROR,
"failed to find _RETURN rule for view");
2477 elog(
ERROR,
"unrecognized CmdType: %d", (
int) event);
2510 return gettext_noop(
"Junk view columns are not updatable.");
2515 return gettext_noop(
"View columns that are not columns of their base relation are not updatable.");
2518 return gettext_noop(
"View columns that refer to system columns are not updatable.");
2521 return gettext_noop(
"View columns that return whole-row references are not updatable.");
2582 return gettext_noop(
"Views containing DISTINCT are not automatically updatable.");
2585 return gettext_noop(
"Views containing GROUP BY are not automatically updatable.");
2588 return gettext_noop(
"Views containing HAVING are not automatically updatable.");
2591 return gettext_noop(
"Views containing UNION, INTERSECT, or EXCEPT are not automatically updatable.");
2594 return gettext_noop(
"Views containing WITH are not automatically updatable.");
2597 return gettext_noop(
"Views containing LIMIT or OFFSET are not automatically updatable.");
2608 if (viewquery->hasAggs)
2609 return gettext_noop(
"Views that return aggregate functions are not automatically updatable.");
2611 if (viewquery->hasWindowFuncs)
2612 return gettext_noop(
"Views that return window functions are not automatically updatable.");
2614 if (viewquery->hasTargetSRFs)
2615 return gettext_noop(
"Views that return set-returning functions are not automatically updatable.");
2622 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2626 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2630 (base_rte->
relkind != RELKIND_RELATION &&
2631 base_rte->
relkind != RELKIND_FOREIGN_TABLE &&
2632 base_rte->
relkind != RELKIND_VIEW &&
2633 base_rte->
relkind != RELKIND_PARTITIONED_TABLE))
2634 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2637 return gettext_noop(
"Views containing TABLESAMPLE are not automatically updatable.");
2661 return gettext_noop(
"Views that have no updatable columns are not automatically updatable.");
2695 char **non_updatable_col)
2709 if (updatable_cols != NULL)
2710 *updatable_cols = NULL;
2711 if (non_updatable_col != NULL)
2712 *non_updatable_col = NULL;
2719 const char *col_update_detail;
2724 if (col_update_detail == NULL)
2727 if (updatable_cols != NULL)
2733 if (non_updatable_col != NULL)
2734 *non_updatable_col = tle->resname;
2735 return col_update_detail;
2776 List *outer_reloids,
2777 bool include_triggers,
2784 #define ALL_EVENTS ((1 << CMD_INSERT) | (1 << CMD_UPDATE) | (1 << CMD_DELETE))
2808 if (rel->
rd_rel->relkind == RELKIND_RELATION ||
2809 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2817 if (rulelocks != NULL)
2839 if (include_triggers)
2862 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2884 if (rel->
rd_rel->relkind == RELKIND_VIEW)
2903 &updatable_cols, NULL);
2905 if (include_cols != NULL)
2923 if (base_rte->
relkind != RELKIND_RELATION &&
2924 base_rte->
relkind != RELKIND_PARTITIONED_TABLE)
2926 baseoid = base_rte->
relid;
2937 events |= auto_events;
2978 foreach(lc, targetlist)
2999 if (tle != NULL && !tle->resjunk &&
IsA(tle->
expr,
Var))
3007 elog(
ERROR,
"attribute number %d not found in view targetlist",
3029 const char *auto_update_detail;
3040 List *view_targetlist;
3053 auto_update_detail =
3057 if (auto_update_detail)
3064 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3065 errmsg(
"cannot insert into view \"%s\"",
3068 errhint(
"To enable inserting into the view, provide an INSTEAD OF INSERT trigger or an unconditional ON INSERT DO INSTEAD rule.")));
3072 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3073 errmsg(
"cannot update view \"%s\"",
3076 errhint(
"To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule.")));
3080 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3081 errmsg(
"cannot delete from view \"%s\"",
3084 errhint(
"To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule.")));
3103 char *non_updatable_col;
3129 &non_updatable_col);
3130 if (auto_update_detail)
3140 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3141 errmsg(
"cannot insert into column \"%s\" of view \"%s\"",
3148 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3149 errmsg(
"cannot update column \"%s\" of view \"%s\"",
3163 view_rte =
rt_fetch(parsetree->resultRelation, parsetree->
rtable);
3198 if (viewquery->hasSubLinks)
3229 new_rte->
inh =
false;
3323 parsetree = (
Query *)
3325 parsetree->resultRelation,
3340 parsetree->resultRelation,
3343 Assert(parsetree->resultRelation == new_rt_index);
3365 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3368 elog(
ERROR,
"attribute number %d not found in view targetlist",
3380 Index old_exclRelIndex,
3400 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3403 elog(
ERROR,
"attribute number %d not found in view targetlist",
3422 new_exclRte = new_exclNSItem->
p_rte;
3423 new_exclRte->
relkind = RELKIND_COMPOSITE_TYPE;
3449 new_exclRelIndex, 0);
3459 &parsetree->hasSubLinks);
3510 if (!parsetree->hasSubLinks)
3535 if (parsetree->withCheckOptions !=
NIL)
3556 if (has_wco && (cascaded || viewquery->
jointree->
quals != NULL))
3567 parsetree->withCheckOptions =
lcons(wco,
3568 parsetree->withCheckOptions);
3582 if (!parsetree->hasSubLinks &&
3610 bool instead =
false;
3611 bool returning =
false;
3612 bool updatableview =
false;
3613 Query *qual_product = NULL;
3622 foreach(lc1, parsetree->
cteList)
3652 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3653 errmsg(
"DO INSTEAD NOTIFY rules are not supported for data-modifying statements in WITH")));
3656 Assert(!ctequery->canSetTag);
3660 else if (newstuff ==
NIL)
3663 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3664 errmsg(
"DO INSTEAD NOTHING rules are not supported for data-modifying statements in WITH")));
3671 foreach(lc2, newstuff)
3677 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3678 errmsg(
"conditional DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3681 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3682 errmsg(
"DO ALSO rules are not supported for data-modifying statements in WITH")));
3686 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3687 errmsg(
"multi-statement DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3701 int result_relation;
3705 int product_orig_rt_length;
3706 List *product_queries;
3707 bool hasUpdate =
false;
3708 int values_rte_index = 0;
3709 bool defaults_remaining =
false;
3711 result_relation = parsetree->resultRelation;
3712 Assert(result_relation != 0);
3748 if (values_rte != NULL)
3749 elog(
ERROR,
"more than one VALUES RTE found");
3752 values_rte_index = rtr->
rtindex;
3759 Bitmapset *unused_values_attrnos = NULL;
3764 parsetree->override,
3768 &unused_values_attrnos);
3772 unused_values_attrnos))
3773 defaults_remaining =
true;
3781 parsetree->override,
3792 parsetree->override,
3803 parsetree->override,
3818 switch (
action->commandType)
3848 elog(
ERROR,
"unrecognized commandType: %d", (
int) event);
3854 result_relation, parsetree, &hasUpdate);
3873 if (defaults_remaining && product_queries !=
NIL)
3886 foreach(n, product_queries)
3912 elog(
ERROR,
"failed to find VALUES RTE in product query");
3933 rt_entry_relation->
rd_rel->relkind == RELKIND_VIEW &&
3945 if (qual_product != NULL)
3951 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3952 errmsg(
"cannot insert into view \"%s\"",
3954 errdetail(
"Views with conditional DO INSTEAD rules are not automatically updatable."),
3955 errhint(
"To enable inserting into the view, provide an INSTEAD OF INSERT trigger or an unconditional ON INSERT DO INSTEAD rule.")));
3959 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3960 errmsg(
"cannot update view \"%s\"",
3962 errdetail(
"Views with conditional DO INSTEAD rules are not automatically updatable."),
3963 errhint(
"To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule.")));
3967 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3968 errmsg(
"cannot delete from view \"%s\"",
3970 errdetail(
"Views with conditional DO INSTEAD rules are not automatically updatable."),
3971 errhint(
"To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule.")));
3994 product_queries =
lcons(parsetree, product_queries);
3996 product_queries =
lappend(product_queries, parsetree);
4007 updatableview =
true;
4014 if (product_queries !=
NIL)
4019 foreach(n, rewrite_events)
4023 rev->
event == event)
4025 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4026 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
4033 rewrite_events =
lappend(rewrite_events, rev);
4035 foreach(n, product_queries)
4052 product_orig_rt_length);
4066 if ((instead || qual_product != NULL) &&
4074 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4075 errmsg(
"cannot perform INSERT RETURNING on relation \"%s\"",
4077 errhint(
"You need an unconditional ON INSERT DO INSTEAD rule with a RETURNING clause.")));
4081 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4082 errmsg(
"cannot perform UPDATE RETURNING on relation \"%s\"",
4084 errhint(
"You need an unconditional ON UPDATE DO INSTEAD rule with a RETURNING clause.")));
4088 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4089 errmsg(
"cannot perform DELETE RETURNING on relation \"%s\"",
4091 errhint(
"You need an unconditional ON DELETE DO INSTEAD rule with a RETURNING clause.")));
4094 elog(
ERROR,
"unrecognized commandType: %d",
4105 (product_queries !=
NIL || hasUpdate) &&
4108 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4109 errmsg(
"INSERT with ON CONFLICT clause cannot be used with table that has INSERT or UPDATE rules")));
4130 if (qual_product != NULL)
4131 rewritten =
lcons(qual_product, rewritten);
4133 rewritten =
lcons(parsetree, rewritten);
4137 if (qual_product != NULL)
4138 rewritten =
lappend(rewritten, qual_product);
4140 rewritten =
lappend(rewritten, parsetree);
4156 foreach(lc1, rewritten)
4165 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4166 errmsg(
"WITH cannot be used in a query that is rewritten by rules into multiple queries")));
4185 uint64 input_query_id = parsetree->queryId;
4190 bool foundOriginalQuery;
4197 Assert(parsetree->canSetTag);
4214 foreach(l, querylist)
4220 query->queryId = input_query_id;
4222 results =
lappend(results, query);
4242 foundOriginalQuery =
false;
4251 Assert(query->canSetTag);
4252 Assert(!foundOriginalQuery);
4253 foundOriginalQuery =
true;
4254 #ifndef USE_ASSERT_CHECKING
4260 Assert(!query->canSetTag);
4264 lastInstead = query;
4268 if (!foundOriginalQuery && lastInstead != NULL)
4269 lastInstead->canSetTag =
true;
#define InvalidAttrNumber
int bms_next_member(const Bitmapset *a, int prevbit)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
elog(ERROR, "%s: %s", p2, msg)
int errdetail_internal(const char *fmt,...)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
int ExecCleanTargetListLength(List *targetlist)
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
List * lappend_oid(List *list, Oid datum)
bool list_member_oid(const List *list, Oid datum)
List * list_concat(List *list1, const List *list2)
List * lcons(void *datum, List *list)
List * list_concat_copy(const List *list1, const List *list2)
List * list_delete_last(List *list)
Node * get_typdefault(Oid typid)
Alias * makeAlias(const char *aliasname, List *colnames)
Var * makeWholeRowVar(RangeTblEntry *rte, int varno, Index varlevelsup, bool allowScalar)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
TargetEntry * flatCopyTargetEntry(TargetEntry *src_tle)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
Oid exprType(const Node *expr)
Node * strip_implicit_coercions(Node *node)
#define query_tree_walker(q, w, c, f)
#define expression_tree_walker(n, w, c)
#define QTW_IGNORE_RC_SUBQUERIES
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
Node * coerce_to_domain(Node *arg, Oid baseTypeId, int32 baseTypeMod, Oid typeId, CoercionContext ccontext, CoercionForm cformat, int location, bool hideInputCoercion)
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
ParseState * make_parsestate(ParseState *parentParseState)
RTEPermissionInfo * addRTEPermissionInfo(List **rteperminfos, RangeTblEntry *rte)
RowMarkClause * get_parse_rowmark(Query *qry, Index rtindex)
ParseNamespaceItem * addRangeTableEntryForRelation(ParseState *pstate, Relation rel, int lockmode, Alias *alias, bool inh, bool inFromCl)
bool get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum)
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
#define ACL_SELECT_FOR_UPDATE
@ OVERRIDING_SYSTEM_VALUE
void applyLockingClause(Query *qry, Index rtindex, LockClauseStrength strength, LockWaitPolicy waitPolicy, bool pushedDown)
List * BuildOnConflictExcludedTargetlist(Relation targetrel, Index exclRelIndex)
#define rt_fetch(rangetable_index, rangetable)
FormData_pg_attribute * Form_pg_attribute
Oid getIdentitySequence(Oid relid, AttrNumber attnum, bool missing_ok)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
#define foreach_delete_current(lst, cell)
void check_stack_depth(void)
#define RelationGetRelid(relation)
#define RelationHasCheckOption(relation)
#define RelationHasSecurityInvoker(relation)
#define RelationGetNumberOfAttributes(relation)
#define RelationGetRelationName(relation)
#define RelationHasCascadedCheckOption(relation)
#define RelationIsSecurityView(relation)
#define RULE_FIRES_ON_ORIGIN
#define RULE_FIRES_ON_REPLICA
static void markQueryForLocking(Query *qry, Node *jtnode, LockClauseStrength strength, LockWaitPolicy waitPolicy, bool pushedDown)
static Query * rewriteRuleAction(Query *parsetree, Query *rule_action, Node *rule_qual, int rt_index, CmdType event, bool *returning_flag)
static List * fireRules(Query *parsetree, int rt_index, CmdType event, List *locks, bool *instead_flag, bool *returning_flag, Query **qual_product)
static TargetEntry * process_matched_tle(TargetEntry *src_tle, TargetEntry *prior_tle, const char *attrName)
static List * adjustJoinTreeList(Query *parsetree, bool removert, int rt_index)
void AcquireRewriteLocks(Query *parsetree, bool forExecute, bool forUpdatePushedDown)
const char * view_query_is_auto_updatable(Query *viewquery, bool check_cols)
int relation_is_updatable(Oid reloid, List *outer_reloids, bool include_triggers, Bitmapset *include_cols)
static Query * CopyAndAddInvertedQual(Query *parsetree, Node *rule_qual, int rt_index, CmdType event)
List * QueryRewrite(Query *parsetree)
static bool acquireLocksOnSubLinks(Node *node, acquireLocksOnSubLinks_context *context)
static bool rewriteValuesRTE(Query *parsetree, RangeTblEntry *rte, int rti, Relation target_relation, Bitmapset *unused_cols)
static Node * get_assignment_input(Node *node)
static Bitmapset * adjust_view_column_set(Bitmapset *cols, List *targetlist)
struct acquireLocksOnSubLinks_context acquireLocksOnSubLinks_context
static bool fireRIRonSubLink(Node *node, List *activeRIRs)
static bool searchForDefault(RangeTblEntry *rte)
static List * RewriteQuery(Query *parsetree, List *rewrite_events, int orig_rt_length)
struct rewrite_event rewrite_event
static Query * fireRIRrules(Query *parsetree, List *activeRIRs)
static const char * view_cols_are_auto_updatable(Query *viewquery, Bitmapset *required_cols, Bitmapset **updatable_cols, char **non_updatable_col)
static Bitmapset * findDefaultOnlyColumns(RangeTblEntry *rte)
static void rewriteValuesRTEToNulls(Query *parsetree, RangeTblEntry *rte)
Query * get_view_query(Relation view)
static Query * ApplyRetrieveRule(Query *parsetree, RewriteRule *rule, int rt_index, Relation relation, List *activeRIRs)
static List * matchLocks(CmdType event, RuleLock *rulelocks, int varno, Query *parsetree, bool *hasUpdate)
static List * rewriteTargetListIU(List *targetList, CmdType commandType, OverridingKind override, Relation target_relation, RangeTblEntry *values_rte, int values_rte_index, Bitmapset **unused_values_attrnos)
static Query * rewriteTargetView(Query *parsetree, Relation view)
static const char * view_col_is_auto_updatable(RangeTblRef *rtr, TargetEntry *tle)
Node * build_column_default(Relation rel, int attrno)
static bool view_has_instead_trigger(Relation view, CmdType event)
Node * ReplaceVarsFromTargetList(Node *node, int target_varno, int sublevels_up, RangeTblEntry *target_rte, List *targetlist, ReplaceVarsNoMatchOption nomatch_option, int nomatch_varno, bool *outer_hasSubLinks)
void ChangeVarNodes(Node *node, int rt_index, int new_index, int sublevels_up)
void OffsetVarNodes(Node *node, int offset, int sublevels_up)
bool checkExprHasSubLink(Node *node)
Query * getInsertSelectQuery(Query *parsetree, Query ***subquery_ptr)
void CombineRangeTables(List **dst_rtable, List **dst_perminfos, List *src_rtable, List *src_perminfos)
void AddQual(Query *parsetree, Node *qual)
bool rangeTableEntry_used(Node *node, int rt_index, int sublevels_up)
void AddInvertedQual(Query *parsetree, Node *qual)
@ REPLACEVARS_SUBSTITUTE_NULL
@ REPLACEVARS_CHANGE_VARNO
@ REPLACEVARS_REPORT_ERROR
CommonTableExpr * rewriteSearchAndCycle(CommonTableExpr *cte)
void get_row_security_policies(Query *root, RangeTblEntry *rte, int rt_index, List **securityQuals, List **withCheckOptions, bool *hasRowSecurity, bool *hasSubLinks)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation try_relation_open(Oid relationId, LOCKMODE lockmode)
ExecForeignInsert_function ExecForeignInsert
ExecForeignUpdate_function ExecForeignUpdate
ExecForeignDelete_function ExecForeignDelete
IsForeignRelUpdatable_function IsForeignRelUpdatable
OnConflictExpr * onConflict
struct TableSampleClause * tablesample
LockClauseStrength strength
LockWaitPolicy waitPolicy
bool trig_update_instead_row
bool trig_delete_instead_row
bool trig_insert_instead_row
#define FirstLowInvalidHeapAttributeNumber
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
int SessionReplicationRole
#define SESSION_REPLICATION_ROLE_REPLICA
Node * TupleDescGetDefault(TupleDesc tupdesc, AttrNumber attnum)
#define TupleDescAttr(tupdesc, i)
String * makeString(char *str)
bool contain_vars_of_level(Node *node, int levelsup)
static struct rule * rules