MCPcopy Create free account
hub / github.com/apache/cloudberry / markRTEForSelectPriv

Function markRTEForSelectPriv

src/backend/parser/parse_relation.c:1026–1099  ·  view source on GitHub ↗

* markRTEForSelectPriv * Mark the specified column of the RTE with index rtindex * as requiring SELECT privilege * * col == InvalidAttrNumber means a "whole row" reference */

Source from the content-addressed store, hash-verified

1024 * col == InvalidAttrNumber means a "whole row" reference
1025 */
1026static void
1027markRTEForSelectPriv(ParseState *pstate, int rtindex, AttrNumber col)
1028{
1029 RangeTblEntry *rte = rt_fetch(rtindex, pstate->p_rtable);
1030
1031 if (rte->rtekind == RTE_RELATION)
1032 {
1033 /* Make sure the rel as a whole is marked for SELECT access */
1034 rte->requiredPerms |= ACL_SELECT;
1035 /* Must offset the attnum to fit in a bitmapset */
1036 rte->selectedCols = bms_add_member(rte->selectedCols,
1037 col - FirstLowInvalidHeapAttributeNumber);
1038 }
1039 else if (rte->rtekind == RTE_JOIN)
1040 {
1041 if (col == InvalidAttrNumber)
1042 {
1043 /*
1044 * A whole-row reference to a join has to be treated as whole-row
1045 * references to the two inputs.
1046 */
1047 JoinExpr *j;
1048
1049 if (rtindex > 0 && rtindex <= list_length(pstate->p_joinexprs))
1050 j = list_nth_node(JoinExpr, pstate->p_joinexprs, rtindex - 1);
1051 else
1052 j = NULL;
1053 if (j == NULL)
1054 elog(ERROR, "could not find JoinExpr for whole-row reference");
1055
1056 /* Note: we can't see FromExpr here */
1057 if (IsA(j->larg, RangeTblRef))
1058 {
1059 int varno = ((RangeTblRef *) j->larg)->rtindex;
1060
1061 markRTEForSelectPriv(pstate, varno, InvalidAttrNumber);
1062 }
1063 else if (IsA(j->larg, JoinExpr))
1064 {
1065 int varno = ((JoinExpr *) j->larg)->rtindex;
1066
1067 markRTEForSelectPriv(pstate, varno, InvalidAttrNumber);
1068 }
1069 else
1070 elog(ERROR, "unrecognized node type: %d",
1071 (int) nodeTag(j->larg));
1072 if (IsA(j->rarg, RangeTblRef))
1073 {
1074 int varno = ((RangeTblRef *) j->rarg)->rtindex;
1075
1076 markRTEForSelectPriv(pstate, varno, InvalidAttrNumber);
1077 }
1078 else if (IsA(j->rarg, JoinExpr))
1079 {
1080 int varno = ((JoinExpr *) j->rarg)->rtindex;
1081
1082 markRTEForSelectPriv(pstate, varno, InvalidAttrNumber);
1083 }

Callers 1

markVarForSelectPrivFunction · 0.85

Calls 2

bms_add_memberFunction · 0.85
list_lengthFunction · 0.85

Tested by

no test coverage detected