* preprocess_rowmarks - set up PlanRowMarks if needed */
| 2901 | * preprocess_rowmarks - set up PlanRowMarks if needed |
| 2902 | */ |
| 2903 | static void |
| 2904 | preprocess_rowmarks(PlannerInfo *root) |
| 2905 | { |
| 2906 | Query *parse = root->parse; |
| 2907 | Bitmapset *rels; |
| 2908 | List *prowmarks; |
| 2909 | ListCell *l; |
| 2910 | int i; |
| 2911 | |
| 2912 | if (parse->rowMarks) |
| 2913 | { |
| 2914 | /* |
| 2915 | * We've got trouble if FOR [KEY] UPDATE/SHARE appears inside |
| 2916 | * grouping, since grouping renders a reference to individual tuple |
| 2917 | * CTIDs invalid. This is also checked at parse time, but that's |
| 2918 | * insufficient because of rule substitution, query pullup, etc. |
| 2919 | */ |
| 2920 | CheckSelectLocking(parse, linitial_node(RowMarkClause, |
| 2921 | parse->rowMarks)->strength); |
| 2922 | } |
| 2923 | else |
| 2924 | { |
| 2925 | /* |
| 2926 | * We only need rowmarks for UPDATE, DELETE, or FOR [KEY] |
| 2927 | * UPDATE/SHARE. |
| 2928 | */ |
| 2929 | if (parse->commandType != CMD_UPDATE && |
| 2930 | parse->commandType != CMD_DELETE) |
| 2931 | return; |
| 2932 | } |
| 2933 | |
| 2934 | /* |
| 2935 | * We need to have rowmarks for all base relations except the target. We |
| 2936 | * make a bitmapset of all base rels and then remove the items we don't |
| 2937 | * need or have FOR [KEY] UPDATE/SHARE marks for. |
| 2938 | */ |
| 2939 | rels = get_relids_in_jointree((Node *) parse->jointree, false); |
| 2940 | if (parse->resultRelation) |
| 2941 | rels = bms_del_member(rels, parse->resultRelation); |
| 2942 | |
| 2943 | /* |
| 2944 | * Convert RowMarkClauses to PlanRowMark representation. |
| 2945 | */ |
| 2946 | prowmarks = NIL; |
| 2947 | foreach(l, parse->rowMarks) |
| 2948 | { |
| 2949 | RowMarkClause *rc = lfirst_node(RowMarkClause, l); |
| 2950 | RangeTblEntry *rte = rt_fetch(rc->rti, parse->rtable); |
| 2951 | PlanRowMark *newrc; |
| 2952 | |
| 2953 | /* |
| 2954 | * Currently, it is syntactically impossible to have FOR UPDATE et al |
| 2955 | * applied to an update/delete target rel. If that ever becomes |
| 2956 | * possible, we should drop the target from the PlanRowMark list. |
| 2957 | */ |
| 2958 | Assert(rc->rti != parse->resultRelation); |
| 2959 | |
| 2960 | /* |
no test coverage detected