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 if (sub_action->hasSubLinks)
499 sub_action->hasRowSecurity |= parsetree->hasRowSecurity;
526 if (newjointree !=
NIL)
536 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
537 errmsg(
"conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
546 if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
547 sub_action->hasSubLinks =
569 foreach(lc, parsetree->
cteList)
574 foreach(lc2, sub_action->
cteList)
580 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
581 errmsg(
"WITH query name \"%s\" appears in both a rule action and the query being rewritten",
590 sub_action->hasRecursive |= parsetree->hasRecursive;
591 sub_action->hasModifyingCTE |= parsetree->hasModifyingCTE;
605 if (sub_action->hasModifyingCTE && rule_action != sub_action)
607 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
608 errmsg(
"INSERT ... SELECT rule actions are not supported for queries having data-modifying statements in WITH")));
616 AddQual(sub_action, rule_qual);
631 sub_action = (
Query *)
643 *sub_action_ptr = sub_action;
645 rule_action = sub_action;
660 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
661 errmsg(
"cannot have RETURNING lists in multiple rules")));
662 *returning_flag =
true;
665 parsetree->resultRelation,
672 &rule_action->hasSubLinks);
678 if (parsetree->hasSubLinks && !rule_action->hasSubLinks)
679 rule_action->hasSubLinks =
702 foreach(l, newjointree)
762 int values_rte_index,
786 next_junk_attrno = numattrs + 1;
788 foreach(temp, targetList)
792 if (!old_tle->resjunk)
795 attrno = old_tle->
resno;
796 if (attrno < 1 || attrno > numattrs)
797 elog(
ERROR,
"bogus resno %d in targetlist", attrno);
801 if (att_tup->attisdropped)
805 new_tles[attrno - 1] =
807 new_tles[attrno - 1],
822 if (old_tle->
resno != next_junk_attrno)
825 old_tle->
resno = next_junk_attrno;
827 junk_tlist =
lappend(junk_tlist, old_tle);
832 for (attrno = 1; attrno <= numattrs; attrno++)
840 if (att_tup->attisdropped)
848 apply_default = ((new_tle == NULL && commandType ==
CMD_INSERT) ||
853 int values_attrno = 0;
856 if (values_rte && new_tle &&
IsA(new_tle->
expr,
Var))
860 if (var->
varno == values_rte_index)
869 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS && !apply_default)
872 apply_default =
true;
881 if (values_attrno != 0)
883 if (default_only_cols == NULL)
887 apply_default =
true;
892 (
errcode(ERRCODE_GENERATED_ALWAYS),
893 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
895 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
897 errhint(
"Use OVERRIDING SYSTEM VALUE to override.")));
906 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_BY_DEFAULT &&
908 apply_default =
true;
914 if (att_tup->attgenerated && !apply_default)
920 if (values_attrno != 0)
922 if (default_only_cols == NULL)
926 apply_default =
true;
931 (
errcode(ERRCODE_GENERATED_ALWAYS),
932 errmsg(
"cannot insert a non-DEFAULT value into column \"%s\"",
934 errdetail(
"Column \"%s\" is a generated column.",
943 if (values_attrno != 0 && apply_default && unused_values_attrnos)
955 if (att_tup->attidentity == ATTRIBUTE_IDENTITY_ALWAYS &&
956 new_tle && !apply_default)
958 (
errcode(ERRCODE_GENERATED_ALWAYS),
959 errmsg(
"column \"%s\" can only be updated to DEFAULT",
961 errdetail(
"Column \"%s\" is an identity column defined as GENERATED ALWAYS.",
964 if (att_tup->attgenerated && new_tle && !apply_default)
966 (
errcode(ERRCODE_GENERATED_ALWAYS),
967 errmsg(
"column \"%s\" can only be updated to DEFAULT",
969 errdetail(
"Column \"%s\" is a generated column.",
973 if (att_tup->attgenerated)
980 else if (apply_default)
1001 att_tup->attcollation,
1025 new_tlist =
lappend(new_tlist, new_tle);
1043 const char *attrName)
1054 if (prior_tle == NULL)
1094 prior_expr = (
Node *) prior_tle->
expr;
1109 if (src_input == NULL ||
1110 prior_input == NULL ||
1113 (
errcode(ERRCODE_SYNTAX_ERROR),
1114 errmsg(
"multiple assignments to same column \"%s\"",
1120 priorbottom = prior_input;
1125 if (newbottom == NULL)
1127 priorbottom = newbottom;
1129 if (!
equal(priorbottom, src_input))
1131 (
errcode(ERRCODE_SYNTAX_ERROR),
1132 errmsg(
"multiple assignments to same column \"%s\"",
1145 memcpy(fstore, prior_expr,
sizeof(
FieldStore));
1156 memcpy(fstore, src_expr,
sizeof(
FieldStore));
1157 fstore->
arg = (
Expr *) prior_expr;
1159 newexpr = (
Node *) fstore;
1167 newexpr = (
Node *) sbsref;
1181 newcoerce->
arg = (
Expr *) newexpr;
1182 newexpr = (
Node *) newcoerce;
1227 Oid atttype = att_tup->atttypid;
1228 int32 atttypmod = att_tup->atttypmod;
1232 if (att_tup->attidentity)
1237 nve->
typeId = att_tup->atttypid;
1239 return (
Node *) nve;
1245 if (att_tup->atthasdef)
1254 if (attrno == defval[ndef].adnum)
1263 elog(
ERROR,
"default expression not found for attribute %d of relation \"%s\"",
1271 if (expr == NULL && !att_tup->attgenerated)
1294 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1295 errmsg(
"column \"%s\" is of type %s"
1296 " but default expression is of type %s",
1300 errhint(
"You will need to rewrite or cast the expression.")));
1317 foreach(lc2, sublist)
1345 if (default_only_cols == NULL)
1349 foreach(lc2, sublist)
1362 foreach(lc2, sublist)
1380 return default_only_cols;
1428 bool isAutoUpdatableView;
1453 attrnos = (
int *)
palloc0(numattrs *
sizeof(
int));
1467 Assert(attrno >= 1 && attrno <= numattrs);
1468 attrnos[attrno - 1] = tle->
resno;
1478 isAutoUpdatableView =
false;
1479 if (target_relation->
rd_rel->relkind == RELKIND_VIEW &&
1489 parsetree->resultRelation, parsetree, &hasUpdate);
1497 rule_lock->
qual == NULL)
1510 isAutoUpdatableView =
true;
1525 foreach(lc2, sublist)
1528 int attrno = attrnos[
i++];
1552 elog(
ERROR,
"cannot set value in column %d to DEFAULT",
i);
1553 Assert(attrno > 0 && attrno <= target_relation->rd_att->natts);
1556 if (!att_tup->attisdropped)
1568 if (isAutoUpdatableView)
1571 newList =
lappend(newList, col);
1572 allReplaced =
false;
1578 att_tup->attcollation,
1592 newList =
lappend(newList, new_expr);
1595 newList =
lappend(newList, col);
1597 newValues =
lappend(newValues, newList);
1629 foreach(lc2, sublist)
1642 newList =
lappend(newList, col);
1644 newValues =
lappend(newValues, newList);
1665 if (rulelocks == NULL)
1674 if (parsetree->resultRelation != varno)
1680 for (
i = 0;
i < nlocks;
i++)
1709 if (oneLock->
event == event)
1713 matching_locks =
lappend(matching_locks, oneLock);
1717 return matching_locks;
1737 elog(
ERROR,
"expected just one rule action");
1738 if (
rule->qual != NULL)
1739 elog(
ERROR,
"cannot handle qualified ON SELECT rule");
1741 if (rt_index == parsetree->resultRelation)
1785 parsetree->resultRelation, 0);
1804 elog(
ERROR,
"unrecognized commandType: %d",
1915 strength, waitPolicy,
true);
1935 elog(
ERROR,
"unrecognized node type: %d",
1973 (
void *) activeRIRs);
1987 int origResultRelation = parsetree->resultRelation;
1997 foreach(lc, parsetree->
cteList)
2001 if (cte->search_clause || cte->cycle_clause)
2053 if (rte->
relkind == RELKIND_MATVIEW)
2074 if (rt_index != parsetree->resultRelation &&
2082 if (rt_index == parsetree->resultRelation &&
2083 rt_index != origResultRelation)
2099 for (
i = 0;
i <
rules->numLocks;
i++)
2117 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2118 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
2141 foreach(lc, parsetree->
cteList)
2153 if (parsetree->hasSubLinks)
2164 foreach(lc, parsetree->
rtable)
2168 List *securityQuals;
2169 List *withCheckOptions;
2170 bool hasRowSecurity;
2177 (rte->
relkind != RELKIND_RELATION &&
2178 rte->
relkind != RELKIND_PARTITIONED_TABLE))
2187 &securityQuals, &withCheckOptions,
2188 &hasRowSecurity, &hasSubLinks);
2190 if (securityQuals !=
NIL || withCheckOptions !=
NIL)
2202 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
2203 errmsg(
"infinite recursion detected in policy for relation \"%s\"",
2243 parsetree->withCheckOptions =
list_concat(withCheckOptions,
2244 parsetree->withCheckOptions);
2252 parsetree->hasRowSecurity =
true;
2254 parsetree->hasSubLinks =
true;
2310 &parsetree->hasSubLinks);
2352 bool *returning_flag,
2353 Query **qual_product)
2361 Node *event_qual = rule_lock->
qual;
2369 if (event_qual != NULL)
2374 *instead_flag =
true;
2396 if (*qual_product == NULL)
2414 event_qual, rt_index, event,
2417 rule_action->querySource = qsrc;
2418 rule_action->canSetTag =
false;
2420 results =
lappend(results, rule_action);
2452 elog(
ERROR,
"invalid _RETURN rule action specification");
2458 elog(
ERROR,
"failed to find _RETURN rule for view");
2490 elog(
ERROR,
"unrecognized CmdType: %d", (
int) event);
2523 return gettext_noop(
"Junk view columns are not updatable.");
2528 return gettext_noop(
"View columns that are not columns of their base relation are not updatable.");
2531 return gettext_noop(
"View columns that refer to system columns are not updatable.");
2534 return gettext_noop(
"View columns that return whole-row references are not updatable.");
2595 return gettext_noop(
"Views containing DISTINCT are not automatically updatable.");
2598 return gettext_noop(
"Views containing GROUP BY are not automatically updatable.");
2601 return gettext_noop(
"Views containing HAVING are not automatically updatable.");
2604 return gettext_noop(
"Views containing UNION, INTERSECT, or EXCEPT are not automatically updatable.");
2607 return gettext_noop(
"Views containing WITH are not automatically updatable.");
2610 return gettext_noop(
"Views containing LIMIT or OFFSET are not automatically updatable.");
2621 if (viewquery->hasAggs)
2622 return gettext_noop(
"Views that return aggregate functions are not automatically updatable.");
2624 if (viewquery->hasWindowFuncs)
2625 return gettext_noop(
"Views that return window functions are not automatically updatable.");
2627 if (viewquery->hasTargetSRFs)
2628 return gettext_noop(
"Views that return set-returning functions are not automatically updatable.");
2635 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2639 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2643 (base_rte->
relkind != RELKIND_RELATION &&
2644 base_rte->
relkind != RELKIND_FOREIGN_TABLE &&
2645 base_rte->
relkind != RELKIND_VIEW &&
2646 base_rte->
relkind != RELKIND_PARTITIONED_TABLE))
2647 return gettext_noop(
"Views that do not select from a single table or view are not automatically updatable.");
2650 return gettext_noop(
"Views containing TABLESAMPLE are not automatically updatable.");
2674 return gettext_noop(
"Views that have no updatable columns are not automatically updatable.");
2708 char **non_updatable_col)
2722 if (updatable_cols != NULL)
2723 *updatable_cols = NULL;
2724 if (non_updatable_col != NULL)
2725 *non_updatable_col = NULL;
2732 const char *col_update_detail;
2737 if (col_update_detail == NULL)
2740 if (updatable_cols != NULL)
2746 if (non_updatable_col != NULL)
2747 *non_updatable_col = tle->resname;
2748 return col_update_detail;
2789 List *outer_reloids,
2790 bool include_triggers,
2797 #define ALL_EVENTS ((1 << CMD_INSERT) | (1 << CMD_UPDATE) | (1 << CMD_DELETE))
2821 if (rel->
rd_rel->relkind == RELKIND_RELATION ||
2822 rel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
2830 if (rulelocks != NULL)
2852 if (include_triggers)
2875 if (rel->
rd_rel->relkind == RELKIND_FOREIGN_TABLE)
2897 if (rel->
rd_rel->relkind == RELKIND_VIEW)
2916 &updatable_cols, NULL);
2918 if (include_cols != NULL)
2936 if (base_rte->
relkind != RELKIND_RELATION &&
2937 base_rte->
relkind != RELKIND_PARTITIONED_TABLE)
2939 baseoid = base_rte->
relid;
2950 events |= auto_events;
2991 foreach(lc, targetlist)
3012 if (tle != NULL && !tle->resjunk &&
IsA(tle->
expr,
Var))
3020 elog(
ERROR,
"attribute number %d not found in view targetlist",
3042 const char *auto_update_detail;
3053 List *view_targetlist;
3066 auto_update_detail =
3070 if (auto_update_detail)
3077 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3078 errmsg(
"cannot insert into view \"%s\"",
3081 errhint(
"To enable inserting into the view, provide an INSTEAD OF INSERT trigger or an unconditional ON INSERT DO INSTEAD rule.")));
3085 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3086 errmsg(
"cannot update view \"%s\"",
3089 errhint(
"To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule.")));
3093 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3094 errmsg(
"cannot delete from view \"%s\"",
3097 errhint(
"To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule.")));
3116 char *non_updatable_col;
3142 &non_updatable_col);
3143 if (auto_update_detail)
3153 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3154 errmsg(
"cannot insert into column \"%s\" of view \"%s\"",
3161 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3162 errmsg(
"cannot update column \"%s\" of view \"%s\"",
3176 view_rte =
rt_fetch(parsetree->resultRelation, parsetree->
rtable);
3211 if (viewquery->hasSubLinks)
3242 new_rte->
inh =
false;
3336 parsetree = (
Query *)
3338 parsetree->resultRelation,
3344 &parsetree->hasSubLinks);
3353 parsetree->resultRelation,
3356 Assert(parsetree->resultRelation == new_rt_index);
3378 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3381 elog(
ERROR,
"attribute number %d not found in view targetlist",
3393 Index old_exclRelIndex,
3413 if (view_tle != NULL && !view_tle->resjunk &&
IsA(view_tle->
expr,
Var))
3416 elog(
ERROR,
"attribute number %d not found in view targetlist",
3435 new_exclRte = new_exclNSItem->
p_rte;
3436 new_exclRte->
relkind = RELKIND_COMPOSITE_TYPE;
3462 new_exclRelIndex, 0);
3472 &parsetree->hasSubLinks);
3523 if (!parsetree->hasSubLinks)
3548 if (parsetree->withCheckOptions !=
NIL)
3569 if (has_wco && (cascaded || viewquery->
jointree->
quals != NULL))
3580 parsetree->withCheckOptions =
lcons(wco,
3581 parsetree->withCheckOptions);
3595 if (!parsetree->hasSubLinks &&
3623 bool instead =
false;
3624 bool returning =
false;
3625 bool updatableview =
false;
3626 Query *qual_product = NULL;
3635 foreach(lc1, parsetree->
cteList)
3665 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3666 errmsg(
"DO INSTEAD NOTIFY rules are not supported for data-modifying statements in WITH")));
3669 Assert(!ctequery->canSetTag);
3673 else if (newstuff ==
NIL)
3676 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3677 errmsg(
"DO INSTEAD NOTHING rules are not supported for data-modifying statements in WITH")));
3684 foreach(lc2, newstuff)
3690 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3691 errmsg(
"conditional DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3694 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3695 errmsg(
"DO ALSO rules are not supported for data-modifying statements in WITH")));
3699 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
3700 errmsg(
"multi-statement DO INSTEAD rules are not supported for data-modifying statements in WITH")));
3714 int result_relation;
3718 int product_orig_rt_length;
3719 List *product_queries;
3720 bool hasUpdate =
false;
3721 int values_rte_index = 0;
3722 bool defaults_remaining =
false;
3724 result_relation = parsetree->resultRelation;
3725 Assert(result_relation != 0);
3761 if (values_rte != NULL)
3762 elog(
ERROR,
"more than one VALUES RTE found");
3765 values_rte_index = rtr->
rtindex;
3772 Bitmapset *unused_values_attrnos = NULL;
3777 parsetree->override,
3781 &unused_values_attrnos);
3785 unused_values_attrnos))
3786 defaults_remaining =
true;
3794 parsetree->override,
3805 parsetree->override,
3816 parsetree->override,
3831 switch (
action->commandType)
3861 elog(
ERROR,
"unrecognized commandType: %d", (
int) event);
3867 result_relation, parsetree, &hasUpdate);
3886 if (defaults_remaining && product_queries !=
NIL)
3899 foreach(n, product_queries)
3925 elog(
ERROR,
"failed to find VALUES RTE in product query");
3946 rt_entry_relation->
rd_rel->relkind == RELKIND_VIEW &&
3958 if (qual_product != NULL)
3964 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3965 errmsg(
"cannot insert into view \"%s\"",
3967 errdetail(
"Views with conditional DO INSTEAD rules are not automatically updatable."),
3968 errhint(
"To enable inserting into the view, provide an INSTEAD OF INSERT trigger or an unconditional ON INSERT DO INSTEAD rule.")));
3972 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3973 errmsg(
"cannot update view \"%s\"",
3975 errdetail(
"Views with conditional DO INSTEAD rules are not automatically updatable."),
3976 errhint(
"To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule.")));
3980 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
3981 errmsg(
"cannot delete from view \"%s\"",
3983 errdetail(
"Views with conditional DO INSTEAD rules are not automatically updatable."),
3984 errhint(
"To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule.")));
4007 product_queries =
lcons(parsetree, product_queries);
4009 product_queries =
lappend(product_queries, parsetree);
4020 updatableview =
true;
4027 if (product_queries !=
NIL)
4032 foreach(n, rewrite_events)
4036 rev->
event == event)
4038 (
errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
4039 errmsg(
"infinite recursion detected in rules for relation \"%s\"",
4046 rewrite_events =
lappend(rewrite_events, rev);
4048 foreach(n, product_queries)
4065 product_orig_rt_length);
4079 if ((instead || qual_product != NULL) &&
4087 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4088 errmsg(
"cannot perform INSERT RETURNING on relation \"%s\"",
4090 errhint(
"You need an unconditional ON INSERT DO INSTEAD rule with a RETURNING clause.")));
4094 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4095 errmsg(
"cannot perform UPDATE RETURNING on relation \"%s\"",
4097 errhint(
"You need an unconditional ON UPDATE DO INSTEAD rule with a RETURNING clause.")));
4101 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4102 errmsg(
"cannot perform DELETE RETURNING on relation \"%s\"",
4104 errhint(
"You need an unconditional ON DELETE DO INSTEAD rule with a RETURNING clause.")));
4107 elog(
ERROR,
"unrecognized commandType: %d",
4118 (product_queries !=
NIL || hasUpdate) &&
4121 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4122 errmsg(
"INSERT with ON CONFLICT clause cannot be used with table that has INSERT or UPDATE rules")));
4143 if (qual_product != NULL)
4144 rewritten =
lcons(qual_product, rewritten);
4146 rewritten =
lcons(parsetree, rewritten);
4150 if (qual_product != NULL)
4151 rewritten =
lappend(rewritten, qual_product);
4153 rewritten =
lappend(rewritten, parsetree);
4169 foreach(lc1, rewritten)
4178 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
4179 errmsg(
"WITH cannot be used in a query that is rewritten by rules into multiple queries")));
4198 uint64 input_query_id = parsetree->queryId;
4203 bool foundOriginalQuery;
4210 Assert(parsetree->canSetTag);
4227 foreach(l, querylist)
4233 query->queryId = input_query_id;
4235 results =
lappend(results, query);
4255 foundOriginalQuery =
false;
4264 Assert(query->canSetTag);
4265 Assert(!foundOriginalQuery);
4266 foundOriginalQuery =
true;
4267 #ifndef USE_ASSERT_CHECKING
4273 Assert(!query->canSetTag);
4277 lastInstead = query;
4281 if (!foundOriginalQuery && lastInstead != NULL)
4282 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)
void * stringToNode(const char *str)
#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
#define TupleDescAttr(tupdesc, i)
String * makeString(char *str)
bool contain_vars_of_level(Node *node, int levelsup)
static struct rule * rules