← Back to Overview

src/backend/parser/parse_relation.c

Coverage: 48/50 lines (96.0%)
Total Lines
50
modified
Covered
48
96.0%
Uncovered
2
4.0%
키보드 네비게이션
addRangeTableEntry() lines 1483-1575
Modified Lines Coverage: 2/2 lines (100.0%)
LineHitsSourceCommit
1483 - addRangeTableEntry(ParseState *pstate, -
1484 - RangeVar *relation, -
1485 - Alias *alias, -
1486 - bool inh, -
1487 - bool inFromCl) -
1488 - { -
1489 - RangeTblEntry *rte = makeNode(RangeTblEntry); -
1490 - RTEPermissionInfo *perminfo; -
1491 - char *refname = alias ? alias->aliasname : relation->relname; -
1492 - LOCKMODE lockmode; -
1493 - Relation rel; -
1494 - ParseNamespaceItem *nsitem; -
1495 - -
1496 - Assert(pstate != NULL); -
1497 - -
1498 - rte->rtekind = RTE_RELATION; -
1499 - rte->alias = alias; -
1500 - -
1501 - /* -
1502 - * Identify the type of lock we'll need on this relation. It's not the -
1503 - * query's target table (that case is handled elsewhere), so we need -
1504 - * either RowShareLock if it's locked by FOR UPDATE/SHARE, or plain -
1505 - * AccessShareLock otherwise. -
1506 - */ -
1507 - lockmode = isLockedRefname(pstate, refname) ? RowShareLock : AccessShareLock; -
1508 - -
1509 - /* -
1510 - * Get the rel's OID. This access also ensures that we have an up-to-date -
1511 - * relcache entry for the rel. Since this is typically the first access -
1512 - * to a rel in a statement, we must open the rel with the proper lockmode. -
1513 - */ -
1514 - rel = parserOpenTable(pstate, relation, lockmode); -
1515 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1516 - /* 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1517 - * validate_relation_kind() already catches indexes and composite types, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1518 - * but we use table_openrv_extended() elsewhere for open a property graph 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1519 - * reference, which is not allowed here. Use similar error message as 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1520 - * validate_relation_kind(). 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1521 - */ 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1522 203456 if (rel->rd_rel->relkind == RELKIND_PROPGRAPH) 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1523 3 ereport(ERROR, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1524 - (errcode(ERRCODE_WRONG_OBJECT_TYPE), 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1525 - errmsg("cannot open relation \"%s\"", 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1526 - RelationGetRelationName(rel)), 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1527 - errdetail_relkind_not_supported(rel->rd_rel->relkind))); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1528 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1529 - rte->relid = RelationGetRelid(rel); -
1530 - rte->inh = inh; -
1531 - rte->relkind = rel->rd_rel->relkind; -
1532 - rte->rellockmode = lockmode; -
1533 - -
1534 - /* -
1535 - * Build the list of effective column names using user-supplied aliases -
1536 - * and/or actual column names. -
1537 - */ -
1538 - rte->eref = makeAlias(refname, NIL); -
1539 - buildRelationAliases(rel->rd_att, alias, rte->eref); -
1540 - -
1541 - /* -
1542 - * Set flags and initialize access permissions. -
1543 - * -
1544 - * The initial default on access checks is always check-for-READ-access, -
1545 - * which is the right thing for all except target tables. -
1546 - */ -
1547 - rte->lateral = false; -
1548 - rte->inFromCl = inFromCl; -
1549 - -
1550 - perminfo = addRTEPermissionInfo(&pstate->p_rteperminfos, rte); -
1551 - perminfo->requiredPerms = ACL_SELECT; -
1552 - -
1553 - /* -
1554 - * Add completed RTE to pstate's range table list, so that we know its -
1555 - * index. But we don't add it to the join list --- caller must do that if -
1556 - * appropriate. -
1557 - */ -
1558 - pstate->p_rtable = lappend(pstate->p_rtable, rte); -
1559 - -
1560 - /* -
1561 - * Build a ParseNamespaceItem, but don't add it to the pstate's namespace -
1562 - * list --- caller must do that if appropriate. -
1563 - */ -
1564 - nsitem = buildNSItemFromTupleDesc(rte, list_length(pstate->p_rtable), -
1565 - perminfo, rel->rd_att); -
1566 - -
1567 - /* -
1568 - * Drop the rel refcount, but keep the access lock till end of transaction -
1569 - * so that the table can't be deleted or have its schema modified -
1570 - * underneath us. -
1571 - */ -
1572 - table_close(rel, NoLock); -
1573 - -
1574 - return nsitem; -
1575 - } -
addRangeTableEntryForRelation() lines 1594-1664
Modified Lines Coverage: 2/2 lines (100.0%)
LineHitsSourceCommit
1594 - addRangeTableEntryForRelation(ParseState *pstate, -
1595 - Relation rel, -
1596 - int lockmode, -
1597 - Alias *alias, -
1598 - bool inh, -
1599 - bool inFromCl) -
1600 - { -
1601 - RangeTblEntry *rte = makeNode(RangeTblEntry); -
1602 - RTEPermissionInfo *perminfo; -
1603 - char *refname = alias ? alias->aliasname : RelationGetRelationName(rel); -
1604 - -
1605 - Assert(pstate != NULL); -
1606 - -
1607 - Assert(lockmode == AccessShareLock || -
1608 - lockmode == RowShareLock || -
1609 - lockmode == RowExclusiveLock); -
1610 - Assert(CheckRelationLockedByMe(rel, lockmode, true)); -
1611 - -
1612 - /* 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1613 - * validate_relation_kind() already catches indexes and composite types, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1614 - * but we use table_openrv_extended() elsewhere for open a property graph 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1615 - * reference, which is not allowed here. Use similar error message as 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1616 - * validate_relation_kind(). 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1617 - */ 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1618 118270 if (rel->rd_rel->relkind == RELKIND_PROPGRAPH) 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1619 6 ereport(ERROR, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1620 - (errcode(ERRCODE_WRONG_OBJECT_TYPE), 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1621 - errmsg("cannot open relation \"%s\"", 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1622 - RelationGetRelationName(rel)), 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1623 - errdetail_relkind_not_supported(rel->rd_rel->relkind))); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1624 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
1625 - rte->rtekind = RTE_RELATION; -
1626 - rte->alias = alias; -
1627 - rte->relid = RelationGetRelid(rel); -
1628 - rte->inh = inh; -
1629 - rte->relkind = rel->rd_rel->relkind; -
1630 - rte->rellockmode = lockmode; -
1631 - -
1632 - /* -
1633 - * Build the list of effective column names using user-supplied aliases -
1634 - * and/or actual column names. -
1635 - */ -
1636 - rte->eref = makeAlias(refname, NIL); -
1637 - buildRelationAliases(rel->rd_att, alias, rte->eref); -
1638 - -
1639 - /* -
1640 - * Set flags and initialize access permissions. -
1641 - * -
1642 - * The initial default on access checks is always check-for-READ-access, -
1643 - * which is the right thing for all except target tables. -
1644 - */ -
1645 - rte->lateral = false; -
1646 - rte->inFromCl = inFromCl; -
1647 - -
1648 - perminfo = addRTEPermissionInfo(&pstate->p_rteperminfos, rte); -
1649 - perminfo->requiredPerms = ACL_SELECT; -
1650 - -
1651 - /* -
1652 - * Add completed RTE to pstate's range table list, so that we know its -
1653 - * index. But we don't add it to the join list --- caller must do that if -
1654 - * appropriate. -
1655 - */ -
1656 - pstate->p_rtable = lappend(pstate->p_rtable, rte); -
1657 - -
1658 - /* -
1659 - * Build a ParseNamespaceItem, but don't add it to the pstate's namespace -
1660 - * list --- caller must do that if appropriate. -
1661 - */ -
1662 - return buildNSItemFromTupleDesc(rte, list_length(pstate->p_rtable), -
1663 - perminfo, rel->rd_att); -
1664 - } -
addRangeTableEntryForGraphTable() lines 2168-2258
Modified Lines Coverage: 44/46 lines (95.7%)
LineHitsSourceCommit
2168 351 addRangeTableEntryForGraphTable(ParseState *pstate, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2169 - Oid graphid, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2170 - GraphPattern *graph_pattern, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2171 - List *columns, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2172 - List *colnames, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2173 - Alias *alias, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2174 - bool lateral, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2175 - bool inFromCl) 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2176 - { 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2177 351 RangeTblEntry *rte = makeNode(RangeTblEntry); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2178 351 char *refname = alias ? alias->aliasname : pstrdup("graph_table"); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2179 351 Alias *eref; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2180 351 int numaliases; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2181 351 int varattno; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2182 351 ListCell *lc; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2183 351 List *coltypes = NIL; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2184 351 List *coltypmods = NIL; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2185 351 List *colcollations = NIL; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2186 351 RTEPermissionInfo *perminfo; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2187 351 ParseNamespaceItem *nsitem; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2188 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2189 351 Assert(pstate != NULL); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2190 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2191 351 rte->rtekind = RTE_GRAPH_TABLE; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2192 351 rte->relid = graphid; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2193 351 rte->relkind = RELKIND_PROPGRAPH; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2194 351 rte->graph_pattern = graph_pattern; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2195 351 rte->graph_table_columns = columns; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2196 351 rte->alias = alias; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2197 351 rte->rellockmode = AccessShareLock; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2198 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2199 351 eref = alias ? copyObject(alias) : makeAlias(refname, NIL); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2200 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2201 351 if (!eref->colnames) 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2202 351 eref->colnames = colnames; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2203 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2204 351 numaliases = list_length(eref->colnames); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2205 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2206 - /* fill in any unspecified alias columns */ 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2207 351 varattno = 0; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2208 1281 foreach(lc, colnames) 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2209 - { 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2210 930 varattno++; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2211 930 if (varattno > numaliases) 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2212 0 eref->colnames = lappend(eref->colnames, lfirst(lc)); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2213 - } 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2214 351 if (varattno < numaliases) 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2215 0 ereport(ERROR, 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2216 - (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2217 - errmsg("GRAPH_TABLE \"%s\" has %d columns available but %d columns specified", 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2218 - refname, varattno, numaliases))); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2219 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2220 351 rte->eref = eref; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2221 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2222 1281 foreach(lc, columns) 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2223 - { 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2224 930 TargetEntry *te = lfirst_node(TargetEntry, lc); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2225 930 Node *colexpr = (Node *) te->expr; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2226 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2227 930 coltypes = lappend_oid(coltypes, exprType(colexpr)); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2228 930 coltypmods = lappend_int(coltypmods, exprTypmod(colexpr)); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2229 930 colcollations = lappend_oid(colcollations, exprCollation(colexpr)); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2230 - } 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2231 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2232 - /* 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2233 - * Set flags and access permissions. 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2234 - */ 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2235 351 rte->lateral = lateral; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2236 351 rte->inFromCl = inFromCl; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2237 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2238 351 perminfo = addRTEPermissionInfo(&pstate->p_rteperminfos, rte); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2239 351 perminfo->requiredPerms = ACL_SELECT; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2240 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2241 - /* 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2242 - * Add completed RTE to pstate's range table list, so that we know its 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2243 - * index. But we don't add it to the join list --- caller must do that if 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2244 - * appropriate. 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2245 - */ 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2246 351 pstate->p_rtable = lappend(pstate->p_rtable, rte); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2247 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2248 - /* 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2249 - * Build a ParseNamespaceItem, but don't add it to the pstate's namespace 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2250 - * list --- caller must do that if appropriate. 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2251 - */ 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2252 702 nsitem = buildNSItemFromLists(rte, list_length(pstate->p_rtable), 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2253 - coltypes, coltypmods, colcollations); 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2254 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2255 351 nsitem->p_perminfo = perminfo; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2256 - 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2257 351 return nsitem; 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
2258 - } 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
expandRTE() lines 2867-3229
Modified Lines Coverage: 0/0 lines (0.0%)
LineHitsSourceCommit
2867 - expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, -
2868 - VarReturningType returning_type, -
2869 - int location, bool include_dropped, -
2870 - List **colnames, List **colvars) -
2871 - { -
2872 - int varattno; -
2873 - -
2874 - if (colnames) -
2875 - *colnames = NIL; -
2876 - if (colvars) -
2877 - *colvars = NIL; -
2878 - -
2879 - switch (rte->rtekind) -
2880 - { -
2881 - case RTE_RELATION: -
2882 - /* Ordinary relation RTE */ -
2883 - expandRelation(rte->relid, rte->eref, -
2884 - rtindex, sublevels_up, returning_type, location, -
2885 - include_dropped, colnames, colvars); -
2886 - break; -
2887 - case RTE_SUBQUERY: -
2888 - { -
2889 - /* Subquery RTE */ -
2890 - ListCell *aliasp_item = list_head(rte->eref->colnames); -
2891 - ListCell *tlistitem; -
2892 - -
2893 - varattno = 0; -
2894 - foreach(tlistitem, rte->subquery->targetList) -
2895 - { -
2896 - TargetEntry *te = (TargetEntry *) lfirst(tlistitem); -
2897 - -
2898 - if (te->resjunk) -
2899 - continue; -
2900 - varattno++; -
2901 - Assert(varattno == te->resno); -
2902 - -
2903 - /* -
2904 - * Formerly it was possible for the subquery tlist to have -
2905 - * more non-junk entries than the colnames list does (if -
2906 - * this RTE has been expanded from a view that has more -
2907 - * columns than it did when the current query was parsed). -
2908 - * Now that ApplyRetrieveRule cleans up such cases, we -
2909 - * shouldn't see that anymore, but let's just check. -
2910 - */ -
2911 - if (!aliasp_item) -
2912 - elog(ERROR, "too few column names for subquery %s", -
2913 - rte->eref->aliasname); -
2914 - -
2915 - if (colnames) -
2916 - { -
2917 - char *label = strVal(lfirst(aliasp_item)); -
2918 - -
2919 - *colnames = lappend(*colnames, makeString(pstrdup(label))); -
2920 - } -
2921 - -
2922 - if (colvars) -
2923 - { -
2924 - Var *varnode; -
2925 - -
2926 - varnode = makeVar(rtindex, varattno, -
2927 - exprType((Node *) te->expr), -
2928 - exprTypmod((Node *) te->expr), -
2929 - exprCollation((Node *) te->expr), -
2930 - sublevels_up); -
2931 - varnode->varreturningtype = returning_type; -
2932 - varnode->location = location; -
2933 - -
2934 - *colvars = lappend(*colvars, varnode); -
2935 - } -
2936 - -
2937 - aliasp_item = lnext(rte->eref->colnames, aliasp_item); -
2938 - } -
2939 - } -
2940 - break; -
2941 - case RTE_FUNCTION: -
2942 - { -
2943 - /* Function RTE */ -
2944 - int atts_done = 0; -
2945 - ListCell *lc; -
2946 - -
2947 - foreach(lc, rte->functions) -
2948 - { -
2949 - RangeTblFunction *rtfunc = (RangeTblFunction *) lfirst(lc); -
2950 - TypeFuncClass functypclass; -
2951 - Oid funcrettype = InvalidOid; -
2952 - TupleDesc tupdesc = NULL; -
2953 - -
2954 - /* If it has a coldeflist, it returns RECORD */ -
2955 - if (rtfunc->funccolnames != NIL) -
2956 - functypclass = TYPEFUNC_RECORD; -
2957 - else -
2958 - functypclass = get_expr_result_type(rtfunc->funcexpr, -
2959 - &funcrettype, -
2960 - &tupdesc); -
2961 - -
2962 - if (functypclass == TYPEFUNC_COMPOSITE || -
2963 - functypclass == TYPEFUNC_COMPOSITE_DOMAIN) -
2964 - { -
2965 - /* Composite data type, e.g. a table's row type */ -
2966 - Assert(tupdesc); -
2967 - expandTupleDesc(tupdesc, rte->eref, -
2968 - rtfunc->funccolcount, atts_done, -
2969 - rtindex, sublevels_up, -
2970 - returning_type, location, -
2971 - include_dropped, colnames, colvars); -
2972 - } -
2973 - else if (functypclass == TYPEFUNC_SCALAR) -
2974 - { -
2975 - /* Base data type, i.e. scalar */ -
2976 - if (colnames) -
2977 - *colnames = lappend(*colnames, -
2978 - list_nth(rte->eref->colnames, -
2979 - atts_done)); -
2980 - -
2981 - if (colvars) -
2982 - { -
2983 - Var *varnode; -
2984 - -
2985 - varnode = makeVar(rtindex, atts_done + 1, -
2986 - funcrettype, -
2987 - exprTypmod(rtfunc->funcexpr), -
2988 - exprCollation(rtfunc->funcexpr), -
2989 - sublevels_up); -
2990 - varnode->varreturningtype = returning_type; -
2991 - varnode->location = location; -
2992 - -
2993 - *colvars = lappend(*colvars, varnode); -
2994 - } -
2995 - } -
2996 - else if (functypclass == TYPEFUNC_RECORD) -
2997 - { -
2998 - if (colnames) -
2999 - { -
3000 - List *namelist; -
3001 - -
3002 - /* extract appropriate subset of column list */ -
3003 - namelist = list_copy_tail(rte->eref->colnames, -
3004 - atts_done); -
3005 - namelist = list_truncate(namelist, -
3006 - rtfunc->funccolcount); -
3007 - *colnames = list_concat(*colnames, namelist); -
3008 - } -
3009 - -
3010 - if (colvars) -
3011 - { -
3012 - ListCell *l1; -
3013 - ListCell *l2; -
3014 - ListCell *l3; -
3015 - int attnum = atts_done; -
3016 - -
3017 - forthree(l1, rtfunc->funccoltypes, -
3018 - l2, rtfunc->funccoltypmods, -
3019 - l3, rtfunc->funccolcollations) -
3020 - { -
3021 - Oid attrtype = lfirst_oid(l1); -
3022 - int32 attrtypmod = lfirst_int(l2); -
3023 - Oid attrcollation = lfirst_oid(l3); -
3024 - Var *varnode; -
3025 - -
3026 - attnum++; -
3027 - varnode = makeVar(rtindex, -
3028 - attnum, -
3029 - attrtype, -
3030 - attrtypmod, -
3031 - attrcollation, -
3032 - sublevels_up); -
3033 - varnode->varreturningtype = returning_type; -
3034 - varnode->location = location; -
3035 - *colvars = lappend(*colvars, varnode); -
3036 - } -
3037 - } -
3038 - } -
3039 - else -
3040 - { -
3041 - /* addRangeTableEntryForFunction should've caught this */ -
3042 - elog(ERROR, "function in FROM has unsupported return type"); -
3043 - } -
3044 - atts_done += rtfunc->funccolcount; -
3045 - } -
3046 - -
3047 - /* Append the ordinality column if any */ -
3048 - if (rte->funcordinality) -
3049 - { -
3050 - if (colnames) -
3051 - *colnames = lappend(*colnames, -
3052 - llast(rte->eref->colnames)); -
3053 - -
3054 - if (colvars) -
3055 - { -
3056 - Var *varnode = makeVar(rtindex, -
3057 - atts_done + 1, -
3058 - INT8OID, -
3059 - -1, -
3060 - InvalidOid, -
3061 - sublevels_up); -
3062 - -
3063 - varnode->varreturningtype = returning_type; -
3064 - *colvars = lappend(*colvars, varnode); -
3065 - } -
3066 - } -
3067 - } -
3068 - break; -
3069 - case RTE_JOIN: -
3070 - { -
3071 - /* Join RTE */ -
3072 - ListCell *colname; -
3073 - ListCell *aliasvar; -
3074 - -
3075 - Assert(list_length(rte->eref->colnames) == list_length(rte->joinaliasvars)); -
3076 - -
3077 - varattno = 0; -
3078 - forboth(colname, rte->eref->colnames, aliasvar, rte->joinaliasvars) -
3079 - { -
3080 - Node *avar = (Node *) lfirst(aliasvar); -
3081 - -
3082 - varattno++; -
3083 - -
3084 - /* -
3085 - * During ordinary parsing, there will never be any -
3086 - * deleted columns in the join. While this function is -
3087 - * also used by the rewriter and planner, they do not -
3088 - * currently call it on any JOIN RTEs. Therefore, this -
3089 - * next bit is dead code, but it seems prudent to handle -
3090 - * the case correctly anyway. -
3091 - */ -
3092 - if (avar == NULL) -
3093 - { -
3094 - if (include_dropped) -
3095 - { -
3096 - if (colnames) -
3097 - *colnames = lappend(*colnames, -
3098 - makeString(pstrdup(""))); -
3099 - if (colvars) -
3100 - { -
3101 - /* -
3102 - * Can't use join's column type here (it might -
3103 - * be dropped!); but it doesn't really matter -
3104 - * what type the Const claims to be. -
3105 - */ -
3106 - *colvars = lappend(*colvars, -
3107 - makeNullConst(INT4OID, -1, -
3108 - InvalidOid)); -
3109 - } -
3110 - } -
3111 - continue; -
3112 - } -
3113 - -
3114 - if (colnames) -
3115 - { -
3116 - char *label = strVal(lfirst(colname)); -
3117 - -
3118 - *colnames = lappend(*colnames, -
3119 - makeString(pstrdup(label))); -
3120 - } -
3121 - -
3122 - if (colvars) -
3123 - { -
3124 - Var *varnode; -
3125 - -
3126 - /* -
3127 - * If the joinaliasvars entry is a simple Var, just -
3128 - * copy it (with adjustment of varlevelsup and -
3129 - * location); otherwise it is a JOIN USING column and -
3130 - * we must generate a join alias Var. This matches -
3131 - * the results that expansion of "join.*" by -
3132 - * expandNSItemVars would have produced, if we had -
3133 - * access to the ParseNamespaceItem for the join. -
3134 - */ -
3135 - if (IsA(avar, Var)) -
3136 - { -
3137 - varnode = copyObject((Var *) avar); -
3138 - varnode->varlevelsup = sublevels_up; -
3139 - } -
3140 - else -
3141 - varnode = makeVar(rtindex, varattno, -
3142 - exprType(avar), -
3143 - exprTypmod(avar), -
3144 - exprCollation(avar), -
3145 - sublevels_up); -
3146 - varnode->varreturningtype = returning_type; -
3147 - varnode->location = location; -
3148 - -
3149 - *colvars = lappend(*colvars, varnode); -
3150 - } -
3151 - } -
3152 - } -
3153 - break; -
3154 - case RTE_TABLEFUNC: -
3155 - case RTE_VALUES: -
3156 - case RTE_CTE: -
3157 - case RTE_NAMEDTUPLESTORE: -
3158 - case RTE_GRAPH_TABLE: 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
3159 - { -
3160 - /* Tablefunc, Values, CTE, or ENR RTE */ -
3161 - ListCell *aliasp_item = list_head(rte->eref->colnames); -
3162 - ListCell *lct; -
3163 - ListCell *lcm; -
3164 - ListCell *lcc; -
3165 - -
3166 - varattno = 0; -
3167 - forthree(lct, rte->coltypes, -
3168 - lcm, rte->coltypmods, -
3169 - lcc, rte->colcollations) -
3170 - { -
3171 - Oid coltype = lfirst_oid(lct); -
3172 - int32 coltypmod = lfirst_int(lcm); -
3173 - Oid colcoll = lfirst_oid(lcc); -
3174 - -
3175 - varattno++; -
3176 - -
3177 - if (colnames) -
3178 - { -
3179 - /* Assume there is one alias per output column */ -
3180 - if (OidIsValid(coltype)) -
3181 - { -
3182 - char *label = strVal(lfirst(aliasp_item)); -
3183 - -
3184 - *colnames = lappend(*colnames, -
3185 - makeString(pstrdup(label))); -
3186 - } -
3187 - else if (include_dropped) -
3188 - *colnames = lappend(*colnames, -
3189 - makeString(pstrdup(""))); -
3190 - -
3191 - aliasp_item = lnext(rte->eref->colnames, aliasp_item); -
3192 - } -
3193 - -
3194 - if (colvars) -
3195 - { -
3196 - if (OidIsValid(coltype)) -
3197 - { -
3198 - Var *varnode; -
3199 - -
3200 - varnode = makeVar(rtindex, varattno, -
3201 - coltype, coltypmod, colcoll, -
3202 - sublevels_up); -
3203 - varnode->varreturningtype = returning_type; -
3204 - varnode->location = location; -
3205 - -
3206 - *colvars = lappend(*colvars, varnode); -
3207 - } -
3208 - else if (include_dropped) -
3209 - { -
3210 - /* -
3211 - * It doesn't really matter what type the Const -
3212 - * claims to be. -
3213 - */ -
3214 - *colvars = lappend(*colvars, -
3215 - makeNullConst(INT4OID, -1, -
3216 - InvalidOid)); -
3217 - } -
3218 - } -
3219 - } -
3220 - } -
3221 - break; -
3222 - case RTE_RESULT: -
3223 - case RTE_GROUP: -
3224 - /* These expose no columns, so nothing to do */ -
3225 - break; -
3226 - default: -
3227 - elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind); -
3228 - } -
3229 - } -
get_rte_attribute_is_dropped() lines 3513-3652
Modified Lines Coverage: 0/0 lines (0.0%)
LineHitsSourceCommit
3513 - get_rte_attribute_is_dropped(RangeTblEntry *rte, AttrNumber attnum) -
3514 - { -
3515 - bool result; -
3516 - -
3517 - switch (rte->rtekind) -
3518 - { -
3519 - case RTE_RELATION: -
3520 - { -
3521 - /* -
3522 - * Plain relation RTE --- get the attribute's catalog entry -
3523 - */ -
3524 - HeapTuple tp; -
3525 - Form_pg_attribute att_tup; -
3526 - -
3527 - tp = SearchSysCache2(ATTNUM, -
3528 - ObjectIdGetDatum(rte->relid), -
3529 - Int16GetDatum(attnum)); -
3530 - if (!HeapTupleIsValid(tp)) /* shouldn't happen */ -
3531 - elog(ERROR, "cache lookup failed for attribute %d of relation %u", -
3532 - attnum, rte->relid); -
3533 - att_tup = (Form_pg_attribute) GETSTRUCT(tp); -
3534 - result = att_tup->attisdropped; -
3535 - ReleaseSysCache(tp); -
3536 - } -
3537 - break; -
3538 - case RTE_SUBQUERY: -
3539 - case RTE_TABLEFUNC: -
3540 - case RTE_VALUES: -
3541 - case RTE_CTE: -
3542 - case RTE_GROUP: -
3543 - case RTE_GRAPH_TABLE: 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
3544 - -
3545 - /* -
3546 - * Subselect, Table Functions, Values, CTE, GROUP RTEs, Property 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
3547 - * graph references never have dropped columns 86c14eaWIP: SQL Property Graph Queries (SQL/PGQ)
3548 - */ -
3549 - result = false; -
3550 - break; -
3551 - case RTE_NAMEDTUPLESTORE: -
3552 - { -
3553 - /* Check dropped-ness by testing for valid coltype */ -
3554 - if (attnum <= 0 || -
3555 - attnum > list_length(rte->coltypes)) -
3556 - elog(ERROR, "invalid varattno %d", attnum); -
3557 - result = !OidIsValid((list_nth_oid(rte->coltypes, attnum - 1))); -
3558 - } -
3559 - break; -
3560 - case RTE_JOIN: -
3561 - { -
3562 - /* -
3563 - * A join RTE would not have dropped columns when constructed, -
3564 - * but one in a stored rule might contain columns that were -
3565 - * dropped from the underlying tables, if said columns are -
3566 - * nowhere explicitly referenced in the rule. This will be -
3567 - * signaled to us by a null pointer in the joinaliasvars list. -
3568 - */ -
3569 - Var *aliasvar; -
3570 - -
3571 - if (attnum <= 0 || -
3572 - attnum > list_length(rte->joinaliasvars)) -
3573 - elog(ERROR, "invalid varattno %d", attnum); -
3574 - aliasvar = (Var *) list_nth(rte->joinaliasvars, attnum - 1); -
3575 - -
3576 - result = (aliasvar == NULL); -
3577 - } -
3578 - break; -
3579 - case RTE_FUNCTION: -
3580 - { -
3581 - /* Function RTE */ -
3582 - ListCell *lc; -
3583 - int atts_done = 0; -
3584 - -
3585 - /* -
3586 - * Dropped attributes are only possible with functions that -
3587 - * return named composite types. In such a case we have to -
3588 - * look up the result type to see if it currently has this -
3589 - * column dropped. So first, loop over the funcs until we -
3590 - * find the one that covers the requested column. -
3591 - */ -
3592 - foreach(lc, rte->functions) -
3593 - { -
3594 - RangeTblFunction *rtfunc = (RangeTblFunction *) lfirst(lc); -
3595 - -
3596 - if (attnum > atts_done && -
3597 - attnum <= atts_done + rtfunc->funccolcount) -
3598 - { -
3599 - TupleDesc tupdesc; -
3600 - -
3601 - /* If it has a coldeflist, it returns RECORD */ -
3602 - if (rtfunc->funccolnames != NIL) -
3603 - return false; /* can't have any dropped columns */ -
3604 - -
3605 - tupdesc = get_expr_result_tupdesc(rtfunc->funcexpr, -
3606 - true); -
3607 - if (tupdesc) -
3608 - { -
3609 - /* Composite data type, e.g. a table's row type */ -
3610 - CompactAttribute *att; -
3611 - -
3612 - Assert(tupdesc); -
3613 - Assert(attnum - atts_done <= tupdesc->natts); -
3614 - att = TupleDescCompactAttr(tupdesc, -
3615 - attnum - atts_done - 1); -
3616 - return att->attisdropped; -
3617 - } -
3618 - /* Otherwise, it can't have any dropped columns */ -
3619 - return false; -
3620 - } -
3621 - atts_done += rtfunc->funccolcount; -
3622 - } -
3623 - -
3624 - /* If we get here, must be looking for the ordinality column */ -
3625 - if (rte->funcordinality && attnum == atts_done + 1) -
3626 - return false; -
3627 - -
3628 - /* this probably can't happen ... */ -
3629 - ereport(ERROR, -
3630 - (errcode(ERRCODE_UNDEFINED_COLUMN), -
3631 - errmsg("column %d of relation \"%s\" does not exist", -
3632 - attnum, -
3633 - rte->eref->aliasname))); -
3634 - result = false; /* keep compiler quiet */ -
3635 - } -
3636 - break; -
3637 - case RTE_RESULT: -
3638 - /* this probably can't happen ... */ -
3639 - ereport(ERROR, -
3640 - (errcode(ERRCODE_UNDEFINED_COLUMN), -
3641 - errmsg("column %d of relation \"%s\" does not exist", -
3642 - attnum, -
3643 - rte->eref->aliasname))); -
3644 - result = false; /* keep compiler quiet */ -
3645 - break; -
3646 - default: -
3647 - elog(ERROR, "unrecognized RTE kind: %d", (int) rte->rtekind); -
3648 - result = false; /* keep compiler quiet */ -
3649 - } -
3650 - -
3651 - return result; -
3652 - } -